mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Compare commits
	
		
			235 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 4b47f99829 | ||
|  | 35aaf40003 | ||
|  | cc5b4a1e02 | ||
|  | 7079521e8c | ||
|  | b5025560a5 | ||
|  | 3f4bdd7f0e | ||
|  | e94bb9b549 | ||
|  | 1ddaacbef5 | ||
|  | e8b40518e0 | ||
|  | 0f88cbb41b | ||
|  | 780d137b76 | ||
|  | ad8a9717d1 | ||
|  | 9d6ea6b2f6 | ||
|  | 7559383089 | ||
|  | f84381c927 | ||
|  | cb0122a43f | ||
|  | 6776b20989 | ||
|  | e98d556022 | ||
|  | 5bf18b69d7 | ||
|  | ea17f045a7 | ||
|  | 526f565ea7 | ||
|  | 4aff9d6e73 | ||
|  | bf516d4d21 | ||
|  | ae92e409d9 | ||
|  | 4d017dc8a9 | ||
|  | 707f4e2965 | ||
|  | 1c3bffdc50 | ||
|  | e54ddcb8b0 | ||
|  | ddefb0debc | ||
|  | 92d8dde90d | ||
|  | 1bb0508ddf | ||
|  | a280a326b9 | ||
|  | 683e9b7c2c | ||
|  | a44e5da421 | ||
|  | 8cd2c90ad7 | ||
|  | 5e57a390a2 | ||
|  | 620848272e | ||
|  | 1e86794416 | ||
|  | e36717259b | ||
|  | 75b9238b90 | ||
|  | ce5b20027e | ||
|  | 0de1242c83 | ||
|  | 8bd445ab19 | ||
|  | fdef0de163 | ||
|  | b1b03a4325 | ||
|  | 0587d96474 | ||
|  | c2241567e4 | ||
|  | 7ac24ba418 | ||
|  | c933ffec66 | ||
|  | e587d934b1 | ||
|  | f354e90656 | ||
|  | 1b0bc7ec6e | ||
|  | ee1acb9c00 | ||
|  | 06862a2812 | ||
|  | 5fa87e18db | ||
|  | 77989e2720 | ||
|  | 3a1102fa4e | ||
|  | 8a9974ce53 | ||
|  | 4be8f1ca03 | ||
|  | 1ec2970ee3 | ||
|  | 81b3a22606 | ||
|  | f81a475cc9 | ||
|  | d7ee03d4f9 | ||
|  | c1c06410c2 | ||
|  | 657d16bb60 | ||
|  | e65a4c1010 | ||
|  | e23d3f5661 | ||
|  | e13611f7af | ||
|  | 596cd09489 | ||
|  | 0be5b27d34 | ||
|  | a27471ae55 | ||
|  | e27e3622a8 | ||
|  | e95273b72b | ||
|  | 583d4f3249 | ||
|  | d6967c4516 | ||
|  | 40b3097374 | ||
|  | 1a1f127993 | ||
|  | a0f34a7ce1 | ||
|  | db020db34b | ||
|  | 681167bc1b | ||
|  | 40e49ffc37 | ||
|  | 834b1afb38 | ||
|  | 62d5a1da87 | ||
|  | 8d8308e557 | ||
|  | e1aa63487a | ||
|  | b7fbe110d4 | ||
|  | 58859eb35a | ||
|  | 4b7e1ae1c6 | ||
|  | 3a06a6ac07 | ||
|  | db0f269dc8 | ||
|  | 3cabe6ca5a | ||
|  | d483005219 | ||
|  | fea9bc4e7e | ||
|  | d579992c98 | ||
|  | ad1c61d959 | ||
|  | bb1da31830 | ||
|  | a50949e554 | ||
|  | 14dce8a10b | ||
|  | 1240c8f685 | ||
|  | cc7c2e952c | ||
|  | 409ec2e086 | ||
|  | a7f6848e53 | ||
|  | 4b0b79199d | ||
|  | d1d6c48d9b | ||
|  | 21631780bb | ||
|  | b935e32340 | ||
|  | 72dd064932 | ||
|  | 2e75446665 | ||
|  | be17e4481e | ||
|  | 616c849b1f | ||
|  | 71947c097f | ||
|  | 546787802d | ||
|  | 294d0e388a | ||
|  | 193a1b0325 | ||
|  | 12743217a2 | ||
|  | b252b9da66 | ||
|  | cdef9c3c7e | ||
|  | 71dcebb744 | ||
|  | 25f248c60a | ||
|  | d5cbc17831 | ||
|  | 7a10217511 | ||
|  | 7559efab77 | ||
|  | 8254efbd03 | ||
|  | 4ae24225a5 | ||
|  | 67d9154563 | ||
|  | ad0319c188 | ||
|  | eb650ea3ec | ||
|  | 7eba33e805 | ||
|  | e1cb9d387e | ||
|  | 2ace7c3ca0 | ||
|  | 58014f0592 | ||
|  | 1d4938bb09 | ||
|  | bbf4007c3e | ||
|  | 4d5124fb4c | ||
|  | 14a7cd05b1 | ||
|  | 946be80eef | ||
|  | 9ad8b1a980 | ||
|  | f733216fcb | ||
|  | ffc6139e21 | ||
|  | 571cac6644 | ||
|  | 2738ac5a5c | ||
|  | 7dfde51b84 | ||
|  | 2d2f18e538 | ||
|  | 3af0dd2e3b | ||
|  | 349e077802 | ||
|  | 812aae358f | ||
|  | c3c59d0627 | ||
|  | 89518b412d | ||
|  | f43b026162 | ||
|  | b806c70f52 | ||
|  | 10bff3c0b8 | ||
|  | 65c12fd0b2 | ||
|  | 50f71c4130 | ||
|  | 8e401a53dc | ||
|  | 64a289a47c | ||
|  | 8f2c37061b | ||
|  | 39f2de6b90 | ||
|  | 855ba8d4f3 | ||
|  | 74f098e718 | ||
|  | 56c8a84691 | ||
|  | 8bbf319032 | ||
|  | afbca4ae65 | ||
|  | 0ef6d2f91a | ||
|  | fbe4435599 | ||
|  | 34be565dd1 | ||
|  | af838e4ed1 | ||
|  | 60fe8ce011 | ||
|  | 8ece341467 | ||
|  | dfa6bdbcb8 | ||
|  | fb2481ebaa | ||
|  | 4874c116cf | ||
|  | e19c44efbd | ||
|  | 4b687b9bdc | ||
|  | 6af79ef601 | ||
|  | 352b996ad2 | ||
|  | 4a93bb35f8 | ||
|  | 8e1f493daf | ||
|  | 59ee153375 | ||
|  | 60f7f1fc16 | ||
|  | b7433683d8 | ||
|  | 42799b9273 | ||
|  | 860a0f790e | ||
|  | 8daccbfbb4 | ||
|  | 285b77dcb7 | ||
|  | 6e48827d3f | ||
|  | f0c20cc706 | ||
|  | 8916c0a3de | ||
|  | 7193a77840 | ||
|  | 61930b5b51 | ||
|  | 11a494cacf | ||
|  | 17f9bf0339 | ||
|  | 3d9755ca8c | ||
|  | b5cf2d03e6 | ||
|  | e3b35b8f35 | ||
|  | 1c1fe672bd | ||
|  | 6c71f68ed8 | ||
|  | 8f2f912cdf | ||
|  | bf6ea16acb | ||
|  | 288546c2b9 | ||
|  | 724db6c34c | ||
|  | 067c451c1d | ||
|  | 11e3696191 | ||
|  | 41e20664de | ||
|  | d8de90d6f3 | ||
|  | b01e8299d3 | ||
|  | 1ec11e3e2e | ||
|  | 422f429725 | ||
|  | 5c55fa5fbb | ||
|  | 80d845fdf2 | ||
|  | 601fe68346 | ||
|  | 9e050fb059 | ||
|  | 99d4adf5e6 | ||
|  | 85f8d1e8e9 | ||
|  | 8334d3d99f | ||
|  | cff08d19eb | ||
|  | 2d86390bc1 | ||
|  | 7a20835571 | ||
|  | ff3c9676b5 | ||
|  | 055f97dab1 | ||
|  | 8a867e71a1 | ||
|  | b8275b4734 | ||
|  | 36b951b146 | ||
|  | c5a5f17643 | ||
|  | 16b909c4df | ||
|  | 92b7648e03 | ||
|  | ca46ebe3b2 | ||
|  | 676e48254a | ||
|  | b15b55227d | ||
|  | 3c3b723913 | ||
|  | f05002c729 | ||
|  | 1c2cbd5b40 | ||
|  | 54c6ca9f45 | ||
|  | c10efbb170 | ||
|  | a496ad5814 | ||
|  | f946f10afd | 
							
								
								
									
										25
									
								
								.codeclimate.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								.codeclimate.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| # Save as .codeclimate.yml (note leading .) in project root directory | ||||
| languages: | ||||
|   JavaScript: true | ||||
|   PHP: true | ||||
| exclude_paths: | ||||
| - "public/packages/maximebf/php-debugbar/debugbar.js" | ||||
| - "public/packages/maximebf/php-debugbar/widgets.js" | ||||
| - "public/packages/maximebf/php-debugbar/openhandler.js" | ||||
| - "public/packages/maximebf/php-debugbar/widgets/sqlqueries/widget.js" | ||||
| - "public/js/bootstrap3-typeahead.min.js" | ||||
| - "public/js/bootstrap-sortable.js" | ||||
| - "public/js/bootstrap-tagsinput.min.js" | ||||
| - "public/js/bootstrap-tagsinput.min.js.map" | ||||
| - "public/js/daterangepicker.js" | ||||
| - "public/js/jquery-2.1.3.min.js" | ||||
| - "public/js/jquery-2.1.3.min.js.map" | ||||
| - "public/js/jquery-ui.min.js" | ||||
| - "public/js/metisMenu.js" | ||||
| - "public/js/moment.min.js" | ||||
| - "public/js/sb-admin-2.js" | ||||
| - "public/bootstrap/*" | ||||
| - "resources/lang/*" | ||||
| - "tests/*" | ||||
| - "database/*" | ||||
| - "storage/*" | ||||
| @@ -1,3 +1,3 @@ | ||||
| src_dir: . | ||||
| coverage_clover: storage/coverage/clover.xml | ||||
| json_path: storage/coverage/coveralls-upload.json | ||||
| coverage_clover: build/logs/clover.xml | ||||
| json_path: build/logs/coveralls-upload.json | ||||
|   | ||||
| @@ -16,4 +16,6 @@ EMAIL_DRIVER=smtp | ||||
| EMAIL_USERNAME= | ||||
| EMAIL_PASSWORD= | ||||
| ANALYTICS_ID= | ||||
| EMAIL_PRETEND=false | ||||
| EMAIL_PRETEND=false | ||||
| RUNCLEANUP=true | ||||
| SITE_OWNER=mail@example.com | ||||
							
								
								
									
										22
									
								
								.jshintrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								.jshintrc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| { | ||||
|   "undef": true, | ||||
|   "unused": false, | ||||
|   "strict": true, | ||||
|   "browser": true, | ||||
|   "jquery": true, | ||||
|   "devel": true, | ||||
|   "globals": [ | ||||
|     "language", | ||||
|     "token", | ||||
|     "currencyCode", | ||||
|     "$", | ||||
|     "token", | ||||
|     "accountID", | ||||
|     "billID", | ||||
|     "currentMonthName", | ||||
|     "previousMonthName", | ||||
|     "nextMonthName", | ||||
|     "everything", | ||||
|     "moment" | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										5
									
								
								.scrutinizer.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								.scrutinizer.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| # .scrutinizer.yml | ||||
| tools: | ||||
|   external_code_coverage: | ||||
|     timeout: 1800    # Timeout in seconds. | ||||
|     runs: 2 | ||||
| @@ -6,10 +6,6 @@ php: | ||||
|   - 5.5 | ||||
|   - 5.6 | ||||
|  | ||||
| addons: | ||||
|   code_climate: | ||||
|     repo_token: 26489f9e854fcdf7e7660ba29c1455694685465b1f90329a79f7d2bf448acb61 | ||||
|  | ||||
| install: | ||||
|   - composer update | ||||
|   - php artisan env | ||||
| @@ -20,3 +16,7 @@ script: | ||||
|  | ||||
| after_script: | ||||
|   - php vendor/bin/coveralls | ||||
|   - CODECLIMATE_REPO_TOKEN=26489f9e854fcdf7e7660ba29c1455694685465b1f90329a79f7d2bf448acb61 ./vendor/bin/test-reporter --stdout > codeclimate.json | ||||
|   - "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports" | ||||
|   - wget https://scrutinizer-ci.com/ocular.phar | ||||
|   - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml | ||||
|   | ||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,13 +1,9 @@ | ||||
| # Firefly III | ||||
| #### v3.4.0.8 | ||||
| # Firefly III (v3.4.5) | ||||
|  | ||||
| [](https://scrutinizer-ci.com/g/JC5/firefly-iii/?branch=master) | ||||
| [](https://scrutinizer-ci.com/g/JC5/firefly-iii/?branch=master) | ||||
| [](https://scrutinizer-ci.com/g/JC5/firefly-iii/build-status/master) | ||||
|  | ||||
| [](https://travis-ci.org/JC5/firefly-iii) | ||||
| [](http://stillmaintained.com/JC5/firefly-iii) | ||||
| [](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) | ||||
| [](https://codeclimate.com/github/JC5/firefly-iii) | ||||
| [](https://coveralls.io/r/JC5/firefly-iii?branch=master) | ||||
| [](https://packagist.org/packages/grumpydictator/firefly-iii) | ||||
|  | ||||
| ## About | ||||
|  | ||||
| "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  | ||||
| @@ -30,7 +26,7 @@ To get to know Firefly, and to see if it fits you, check out these resources: | ||||
| and the philosophy behind it. | ||||
|  | ||||
|  | ||||
| #### About the name (if you care) | ||||
| #### About the name (should 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. | ||||
|  | ||||
| @@ -95,3 +91,9 @@ 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). | ||||
|  | ||||
| [](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) | ||||
| [](https://codeclimate.com/github/JC5/firefly-iii) | ||||
| [](http://stillmaintained.com/JC5/firefly-iii) | ||||
| [](https://packagist.org/packages/grumpydictator/firefly-iii) | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
|  | ||||
| use Exception; | ||||
| use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | ||||
| use Symfony\Component\HttpKernel\Exception\HttpException; | ||||
|  | ||||
| /** | ||||
|  * Class Handler | ||||
| @@ -33,7 +34,7 @@ class Handler extends ExceptionHandler | ||||
|      */ | ||||
|     public function render($request, Exception $e) | ||||
|     { | ||||
|         if ($this->isHttpException($e)) { | ||||
|         if ($e instanceof HttpException) { | ||||
|             return $this->renderHttpException($e); | ||||
|         } else { | ||||
|             return parent::render($request, $e); | ||||
|   | ||||
| @@ -4,7 +4,6 @@ use Auth; | ||||
| use FireflyIII\Events\JournalCreated; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\PiggyBankEvent; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
|  | ||||
| /** | ||||
| @@ -18,6 +17,8 @@ class ConnectJournalToPiggyBank | ||||
|     /** | ||||
|      * Create the event handler. | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -51,17 +52,9 @@ class ConnectJournalToPiggyBank | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         $amount = $journal->amount; | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($journal->transactions()->get() as $transaction) { | ||||
|             if ($transaction->account_id == $piggyBank->account_id) { | ||||
|                 if ($transaction->amount < 0) { | ||||
|                     $amount = $transaction->amount * -1; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $repetition->currentamount += $amount; | ||||
|         $amount = $journal->correct_amount; | ||||
|         bcscale(2); | ||||
|         $repetition->currentamount = bcadd($repetition->currentamount, $amount); | ||||
|         $repetition->save(); | ||||
|  | ||||
|         PiggyBankEvent::create(['piggy_bank_id' => $piggyBank->id, 'transaction_journal_id' => $journal->id, 'date' => $journal->date, 'amount' => $amount]); | ||||
|   | ||||
| @@ -50,7 +50,7 @@ class UpdateJournalConnection | ||||
|             return; | ||||
|         } | ||||
|         $amount = $journal->amount; | ||||
|         $diff   = $amount - $event->amount;// update current repetition | ||||
|         $diff   = $amount - $event->amount; // update current repetition | ||||
|  | ||||
|         $repetition->currentamount += $diff; | ||||
|         $repetition->save(); | ||||
|   | ||||
| @@ -64,6 +64,8 @@ class BalanceLine | ||||
|         if ($this->getRole() == self::ROLE_DIFFROLE) { | ||||
|             return trans('firefly.leftUnbalanced'); | ||||
|         } | ||||
|  | ||||
|         return ''; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -157,10 +159,11 @@ class BalanceLine | ||||
|      */ | ||||
|     public function sumOfLeft() | ||||
|     { | ||||
|         $sum = 0.0; | ||||
|         $sum = '0'; | ||||
|         bcscale(2); | ||||
|         /** @var BalanceEntry $balanceEntry */ | ||||
|         foreach ($this->getBalanceEntries() as $balanceEntry) { | ||||
|             $sum += $balanceEntry->getLeft(); | ||||
|             $sum = bcadd($sum, $balanceEntry->getLeft()); | ||||
|         } | ||||
|  | ||||
|         return $sum; | ||||
|   | ||||
| @@ -3,7 +3,6 @@ | ||||
| namespace FireflyIII\Helpers\Collection; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Models\Bill as BillModel; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
| @@ -41,7 +40,7 @@ class Bill | ||||
|      */ | ||||
|     public function getBills() | ||||
|     { | ||||
|         $this->bills->sortBy( | ||||
|         $set = $this->bills->sortBy( | ||||
|             function (BillLine $bill) { | ||||
|                 $active = intval($bill->getBill()->active) == 0 ? 1 : 0; | ||||
|                 $name   = $bill->getBill()->name; | ||||
| @@ -51,7 +50,7 @@ class Bill | ||||
|         ); | ||||
|  | ||||
|  | ||||
|         return $this->bills; | ||||
|         return $set; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -16,19 +16,19 @@ class BillLine | ||||
|  | ||||
|     /** @var  bool */ | ||||
|     protected $active; | ||||
|     /** @var  float */ | ||||
|     /** @var  string */ | ||||
|     protected $amount; | ||||
|     /** @var  BillModel */ | ||||
|     protected $bill; | ||||
|     /** @var  bool */ | ||||
|     protected $hit; | ||||
|     /** @var  float */ | ||||
|     /** @var  string */ | ||||
|     protected $max; | ||||
|     /** @var  float */ | ||||
|     /** @var  string */ | ||||
|     protected $min; | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getAmount() | ||||
|     { | ||||
| @@ -36,7 +36,7 @@ class BillLine | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $amount | ||||
|      * @param string $amount | ||||
|      */ | ||||
|     public function setAmount($amount) | ||||
|     { | ||||
| @@ -60,7 +60,7 @@ class BillLine | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getMax() | ||||
|     { | ||||
| @@ -68,7 +68,7 @@ class BillLine | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $max | ||||
|      * @param string $max | ||||
|      */ | ||||
|     public function setMax($max) | ||||
|     { | ||||
| @@ -76,7 +76,7 @@ class BillLine | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getMin() | ||||
|     { | ||||
| @@ -84,7 +84,7 @@ class BillLine | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $min | ||||
|      * @param string $min | ||||
|      */ | ||||
|     public function setMin($min) | ||||
|     { | ||||
|   | ||||
| @@ -15,14 +15,14 @@ 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; | ||||
|     /** @var string */ | ||||
|     protected $budgeted = '0'; | ||||
|     /** @var string */ | ||||
|     protected $left = '0'; | ||||
|     /** @var string */ | ||||
|     protected $overspent = '0'; | ||||
|     /** @var string */ | ||||
|     protected $spent = '0'; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
| @@ -45,7 +45,9 @@ class Budget | ||||
|      */ | ||||
|     public function addBudgeted($add) | ||||
|     { | ||||
|         $this->budgeted += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->budgeted = bcadd($this->budgeted, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -53,7 +55,9 @@ class Budget | ||||
|      */ | ||||
|     public function addLeft($add) | ||||
|     { | ||||
|         $this->left += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->left = bcadd($this->left, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -61,7 +65,9 @@ class Budget | ||||
|      */ | ||||
|     public function addOverspent($add) | ||||
|     { | ||||
|         $this->overspent += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->overspent = bcadd($this->overspent, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -69,7 +75,9 @@ class Budget | ||||
|      */ | ||||
|     public function addSpent($add) | ||||
|     { | ||||
|         $this->spent += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->spent = bcadd($this->spent, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -81,7 +89,7 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getBudgeted() | ||||
|     { | ||||
| @@ -89,7 +97,7 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $budgeted | ||||
|      * @param string $budgeted | ||||
|      */ | ||||
|     public function setBudgeted($budgeted) | ||||
|     { | ||||
| @@ -97,7 +105,7 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getLeft() | ||||
|     { | ||||
| @@ -105,7 +113,7 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $left | ||||
|      * @param string $left | ||||
|      */ | ||||
|     public function setLeft($left) | ||||
|     { | ||||
| @@ -113,7 +121,7 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getOverspent() | ||||
|     { | ||||
| @@ -121,15 +129,15 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $overspent | ||||
|      * @param string $overspent | ||||
|      */ | ||||
|     public function setOverspent($overspent) | ||||
|     { | ||||
|         $this->overspent = $overspent; | ||||
|         $this->overspent = strval(round($overspent, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getSpent() | ||||
|     { | ||||
| @@ -137,11 +145,11 @@ class Budget | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $spent | ||||
|      * @param string $spent | ||||
|      */ | ||||
|     public function setSpent($spent) | ||||
|     { | ||||
|         $this->spent = $spent; | ||||
|         $this->spent = strval(round($spent, 2)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -17,16 +17,14 @@ 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  LimitRepetition */ | ||||
|     protected $repetition; | ||||
|     /** @var float */ | ||||
|     protected $spent = 0; | ||||
|  | ||||
| @@ -94,22 +92,6 @@ class BudgetLine | ||||
|         $this->overspent = $overspent; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      */ | ||||
|     public function getSpent() | ||||
|     { | ||||
|         return $this->spent; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $spent | ||||
|      */ | ||||
|     public function setSpent($spent) | ||||
|     { | ||||
|         $this->spent = $spent; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return LimitRepetition | ||||
|      */ | ||||
| @@ -126,5 +108,21 @@ class BudgetLine | ||||
|         $this->repetition = $repetition; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      */ | ||||
|     public function getSpent() | ||||
|     { | ||||
|         return $this->spent; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $spent | ||||
|      */ | ||||
|     public function setSpent($spent) | ||||
|     { | ||||
|         $this->spent = $spent; | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,10 +1,4 @@ | ||||
| <?php | ||||
| /** | ||||
|  * Created by PhpStorm. | ||||
|  * User: sander | ||||
|  * Date: 16/05/15 | ||||
|  * Time: 13:09 | ||||
|  */ | ||||
|  | ||||
| namespace FireflyIII\Helpers\Collection; | ||||
|  | ||||
| @@ -24,8 +18,8 @@ class Category | ||||
|  | ||||
|     /** @var  Collection */ | ||||
|     protected $categories; | ||||
|     /** @var float */ | ||||
|     protected $total = 0; | ||||
|     /** @var string */ | ||||
|     protected $total = '0'; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
| @@ -50,7 +44,9 @@ class Category | ||||
|      */ | ||||
|     public function addTotal($add) | ||||
|     { | ||||
|         $this->total += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->total = bcadd($this->total, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -58,22 +54,22 @@ class Category | ||||
|      */ | ||||
|     public function getCategories() | ||||
|     { | ||||
|         $this->categories->sortByDesc( | ||||
|         $set = $this->categories->sortByDesc( | ||||
|             function (CategoryModel $category) { | ||||
|                 return $category->spent; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|  | ||||
|         return $this->categories; | ||||
|         return $set; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getTotal() | ||||
|     { | ||||
|         return $this->total; | ||||
|         return strval(round($this->total, 2)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -17,8 +17,8 @@ class Expense | ||||
| { | ||||
|     /** @var Collection */ | ||||
|     protected $expenses; | ||||
|     /** @var float */ | ||||
|     protected $total; | ||||
|     /** @var string */ | ||||
|     protected $total = '0'; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
| @@ -37,14 +37,15 @@ class Expense | ||||
|         $accountId = $entry->account_id; | ||||
|         if (!$this->expenses->has($accountId)) { | ||||
|             $newObject         = new stdClass; | ||||
|             $newObject->amount = floatval($entry->amount); | ||||
|             $newObject->amount = strval(round($entry->amount, 2)); | ||||
|             $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); | ||||
|             bcscale(2); | ||||
|             $existing         = $this->expenses->get($accountId); | ||||
|             $existing->amount = bcadd($existing->amount, $entry->amount); | ||||
|             $existing->count++; | ||||
|             $this->expenses->put($accountId, $existing); | ||||
|         } | ||||
| @@ -55,7 +56,9 @@ class Expense | ||||
|      */ | ||||
|     public function addToTotal($add) | ||||
|     { | ||||
|         $this->total += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->total = bcadd($this->total, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -63,20 +66,20 @@ class Expense | ||||
|      */ | ||||
|     public function getExpenses() | ||||
|     { | ||||
|         $this->expenses->sortByDesc( | ||||
|         $set = $this->expenses->sortByDesc( | ||||
|             function (stdClass $object) { | ||||
|                 return $object->amount; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         return $this->expenses; | ||||
|         return $set; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getTotal() | ||||
|     { | ||||
|         return $this->total; | ||||
|         return strval(round($this->total, 2)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -18,7 +18,7 @@ class Income | ||||
|  | ||||
|     /** @var Collection */ | ||||
|     protected $incomes; | ||||
|     /** @var float */ | ||||
|     /** @var string */ | ||||
|     protected $total; | ||||
|  | ||||
|     /** | ||||
| @@ -38,14 +38,15 @@ class Income | ||||
|         $accountId = $entry->account_id; | ||||
|         if (!$this->incomes->has($accountId)) { | ||||
|             $newObject         = new stdClass; | ||||
|             $newObject->amount = floatval($entry->amount); | ||||
|             $newObject->amount = strval(round($entry->amount, 2)); | ||||
|             $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); | ||||
|             bcscale(2); | ||||
|             $existing         = $this->incomes->get($accountId); | ||||
|             $existing->amount = bcadd($existing->amount, $entry->amount); | ||||
|             $existing->count++; | ||||
|             $this->incomes->put($accountId, $existing); | ||||
|         } | ||||
| @@ -56,7 +57,9 @@ class Income | ||||
|      */ | ||||
|     public function addToTotal($add) | ||||
|     { | ||||
|         $this->total += floatval($add); | ||||
|         $add = strval(round($add, 2)); | ||||
|         bcscale(2); | ||||
|         $this->total = bcadd($this->total, $add); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -64,21 +67,21 @@ class Income | ||||
|      */ | ||||
|     public function getIncomes() | ||||
|     { | ||||
|         $this->incomes->sortByDesc( | ||||
|         $set = $this->incomes->sortByDesc( | ||||
|             function (stdClass $object) { | ||||
|                 return $object->amount; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         return $this->incomes; | ||||
|         return $set; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getTotal() | ||||
|     { | ||||
|         return $this->total; | ||||
|         return strval(round($this->total, 2)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -5,9 +5,11 @@ namespace FireflyIII\Helpers\Reminders; | ||||
| use Amount; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Config; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\Reminder; | ||||
| use Navigation; | ||||
| use Preferences; | ||||
|  | ||||
| /** | ||||
|  * Class ReminderHelper | ||||
| @@ -154,14 +156,21 @@ class ReminderHelper implements ReminderHelperInterface | ||||
|         $piggyBank = $reminder->remindersable; | ||||
|  | ||||
|         if (is_null($piggyBank)) { | ||||
|             return 'Piggy bank no longer exists.'; | ||||
|             return trans('firefly.piggy_bank_not_exists'); | ||||
|         } | ||||
|  | ||||
|         if (is_null($piggyBank->targetdate)) { | ||||
|             return 'Add money to this piggy bank to reach your target of ' . Amount::format($piggyBank->targetamount); | ||||
|             return trans('firefly.add_any_amount_to_piggy', ['amount' => Amount::format($piggyBank->targetamount)]); | ||||
|         } | ||||
|  | ||||
|         return 'Add ' . Amount::format($reminder->metadata->perReminder) . ' to fill this piggy bank on ' . $piggyBank->targetdate->format('jS F Y'); | ||||
|         $lang = Preferences::get('language', 'en')->data; | ||||
|  | ||||
|         return trans( | ||||
|             'firefly.add_set_amount_to_piggy', | ||||
|             [ | ||||
|                 'amount' => Amount::format($reminder->metadata->perReminder), | ||||
|                 'date'   => $piggyBank->targetdate->formatLocalized(Config::get('firefly.monthAndDay.' . $lang)) | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,6 @@ namespace FireflyIII\Helpers\Reminders; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\PiggyBankRepetition; | ||||
| use FireflyIII\Models\Reminder; | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -34,6 +34,7 @@ class ReportHelper implements ReportHelperInterface | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param ReportQueryInterface $query | ||||
|      * | ||||
|      */ | ||||
| @@ -52,7 +53,7 @@ class ReportHelper implements ReportHelperInterface | ||||
|      * @param Carbon $end | ||||
|      * @param        $shared | ||||
|      * | ||||
|      * @return Account | ||||
|      * @return AccountCollection | ||||
|      */ | ||||
|     public function getAccountReport(Carbon $date, Carbon $end, $shared) | ||||
|     { | ||||
| @@ -64,11 +65,15 @@ class ReportHelper implements ReportHelperInterface | ||||
|         $diff     = 0; | ||||
|  | ||||
|         // remove cash account, if any: | ||||
|         $accounts  =$accounts->filter(function(Account $account) { | ||||
|             if($account->accountType->type != 'Cash account') { | ||||
|                 return $account; | ||||
|         $accounts = $accounts->filter( | ||||
|             function (Account $account) { | ||||
|                 if ($account->accountType->type != 'Cash account') { | ||||
|                     return $account; | ||||
|                 } | ||||
|  | ||||
|                 return null; | ||||
|             } | ||||
|         }); | ||||
|         ); | ||||
|  | ||||
|         // summarize: | ||||
|         foreach ($accounts as $account) { | ||||
| @@ -158,7 +163,8 @@ class ReportHelper implements ReportHelperInterface | ||||
|         foreach ($accounts as $account) { | ||||
|             $spent = $this->query->spentNoBudget($account, $start, $end); | ||||
|             $left  = $tagRepository->coveredByBalancingActs($account, $start, $end); | ||||
|             $diff  = $spent + $left; | ||||
|             bcscale(2); | ||||
|             $diff = bcsub($spent, $left); | ||||
|  | ||||
|             // budget | ||||
|             $budgetEntry = new BalanceEntry; | ||||
| @@ -211,18 +217,19 @@ class ReportHelper implements ReportHelperInterface | ||||
|             $billLine = new BillLine; | ||||
|             $billLine->setBill($bill); | ||||
|             $billLine->setActive(intval($bill->active) == 1); | ||||
|             $billLine->setMin(floatval($bill->amount_min)); | ||||
|             $billLine->setMax(floatval($bill->amount_max)); | ||||
|             $billLine->setMin($bill->amount_min); | ||||
|             $billLine->setMax($bill->amount_max); | ||||
|  | ||||
|             // is hit in period? | ||||
|             bcscale(2); | ||||
|             $set = $repository->getJournalsInRange($bill, $start, $end); | ||||
|             if ($set->count() == 0) { | ||||
|                 $billLine->setHit(false); | ||||
|             } else { | ||||
|                 $billLine->setHit(true); | ||||
|                 $amount = 0; | ||||
|                 $amount = '0'; | ||||
|                 foreach ($set as $entry) { | ||||
|                     $amount += $entry->amount; | ||||
|                     $amount = bcadd($amount, $entry->amount); | ||||
|                 } | ||||
|                 $billLine->setAmount($amount); | ||||
|             } | ||||
|   | ||||
| @@ -3,8 +3,9 @@ | ||||
| namespace FireflyIII\Helpers\Report; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Helpers\Collection\Account; | ||||
| use FireflyIII\Helpers\Collection\Account as AccountCollection; | ||||
| use FireflyIII\Helpers\Collection\Balance; | ||||
| use FireflyIII\Helpers\Collection\Bill as BillCollection; | ||||
| use FireflyIII\Helpers\Collection\Budget as BudgetCollection; | ||||
| use FireflyIII\Helpers\Collection\Category as CategoryCollection; | ||||
| use FireflyIII\Helpers\Collection\Expense; | ||||
| @@ -26,7 +27,7 @@ interface ReportHelperInterface | ||||
|      * @param Carbon  $end | ||||
|      * @param boolean $shared | ||||
|      * | ||||
|      * @return Account | ||||
|      * @return AccountCollection | ||||
|      */ | ||||
|     public function getAccountReport(Carbon $date, Carbon $end, $shared); | ||||
|  | ||||
| @@ -38,7 +39,7 @@ interface ReportHelperInterface | ||||
|      * @param Carbon  $end | ||||
|      * @param boolean $shared | ||||
|      * | ||||
|      * @return Account | ||||
|      * @return BillCollection | ||||
|      */ | ||||
|     public function getBillReport(Carbon $start, Carbon $end, $shared); | ||||
|  | ||||
|   | ||||
| @@ -5,12 +5,10 @@ namespace FireflyIII\Helpers\Report; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Crypt; | ||||
| use DB; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use Illuminate\Database\Eloquent\Builder; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Database\Query\JoinClause; | ||||
| use Illuminate\Support\Collection; | ||||
| use Steam; | ||||
| @@ -74,6 +72,8 @@ class ReportQuery implements ReportQueryInterface | ||||
|                 if ($journal->amount != 0) { | ||||
|                     return $journal; | ||||
|                 } | ||||
|  | ||||
|                 return null; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
| @@ -99,7 +99,6 @@ class ReportQuery implements ReportQueryInterface | ||||
|                 $join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole'); | ||||
|             } | ||||
|             ) | ||||
|                   ->orderBy('accounts.name', 'ASC') | ||||
|                   ->where( | ||||
|                       function (Builder $query) { | ||||
|  | ||||
| @@ -138,7 +137,6 @@ class ReportQuery implements ReportQueryInterface | ||||
|      * 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 | ||||
| @@ -191,6 +189,8 @@ class ReportQuery implements ReportQueryInterface | ||||
|                 if ($journal->amount != 0) { | ||||
|                     return $journal; | ||||
|                 } | ||||
|  | ||||
|                 return null; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
| @@ -229,22 +229,19 @@ class ReportQuery implements ReportQueryInterface | ||||
|      * @param Carbon  $end | ||||
|      * @param bool    $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false) | ||||
|     { | ||||
|         return floatval( | ||||
|         return | ||||
|             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') | ||||
|         ); | ||||
|                 ->whereNull('budget_transaction_journal.budget_id')->get(['transaction_journals.*'])->sum('amount'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -73,7 +73,7 @@ interface ReportQueryInterface | ||||
|      * @param Carbon  $end | ||||
|      * @param bool    $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false); | ||||
|  | ||||
|   | ||||
| @@ -3,11 +3,11 @@ | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Config; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\AccountFormRequest; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use Input; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Session; | ||||
| use Steam; | ||||
| @@ -22,7 +22,7 @@ use View; | ||||
| class AccountController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -39,13 +39,15 @@ class AccountController extends Controller | ||||
|     public function create($what = 'asset') | ||||
|     { | ||||
|         $subTitleIcon = Config::get('firefly.subIconsByIdentifier.' . $what); | ||||
|         $subTitle     = 'Create a new ' . e($what) . ' account'; | ||||
|         $subTitle     = trans('firefly.make_new_' . $what . '_account'); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "create another"). | ||||
|         if (Session::get('accounts.create.fromStore') !== true) { | ||||
|             Session::put('accounts.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('accounts.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'accounts'); | ||||
|         Session::flash('gaEventAction', 'create-' . $what); | ||||
|  | ||||
|         return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle')); | ||||
|  | ||||
| @@ -58,10 +60,13 @@ class AccountController extends Controller | ||||
|      */ | ||||
|     public function delete(Account $account) | ||||
|     { | ||||
|         $subTitle = 'Delete ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; | ||||
|         $typeName = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); | ||||
|         $subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('accounts.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'accounts'); | ||||
|         Session::flash('gaEventAction', 'delete-' . $typeName); | ||||
|  | ||||
|         return view('accounts.delete', compact('account', 'subTitle')); | ||||
|     } | ||||
| @@ -81,7 +86,8 @@ class AccountController extends Controller | ||||
|  | ||||
|         $repository->destroy($account); | ||||
|  | ||||
|         Session::flash('success', 'The ' . e($typeName) . ' account "' . e($name) . '" was deleted.'); | ||||
|         Session::flash('success', trans('firefly.' . $typeName . '_deleted', ['name' => $name])); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::to(Session::get('accounts.delete.url')); | ||||
|     } | ||||
| @@ -90,7 +96,7 @@ class AccountController extends Controller | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * @param Account                    $account | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function edit(AccountRepositoryInterface $repository, Account $account) | ||||
|     { | ||||
| @@ -125,6 +131,8 @@ class AccountController extends Controller | ||||
|             'virtualBalance'       => floatval($account->virtual_balance) | ||||
|         ]; | ||||
|         Session::flash('preFilled', $preFilled); | ||||
|         Session::flash('gaEventCategory', 'accounts'); | ||||
|         Session::flash('gaEventAction', 'edit-' . $what); | ||||
|  | ||||
|         return view('accounts.edit', compact('account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what')); | ||||
|     } | ||||
| @@ -133,7 +141,7 @@ class AccountController extends Controller | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * @param                            $what | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function index(AccountRepositoryInterface $repository, $what) | ||||
|     { | ||||
| @@ -162,7 +170,7 @@ class AccountController extends Controller | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * @param Account                    $account | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function show(AccountRepositoryInterface $repository, Account $account) | ||||
|     { | ||||
| @@ -193,13 +201,14 @@ class AccountController extends Controller | ||||
|             'user'                   => Auth::user()->id, | ||||
|             'accountRole'            => $request->input('accountRole'), | ||||
|             'openingBalance'         => floatval($request->input('openingBalance')), | ||||
|             'openingBalanceDate'     => new Carbon($request->input('openingBalanceDate')), | ||||
|             'openingBalanceDate'     => new Carbon((string)$request->input('openingBalanceDate')), | ||||
|             'openingBalanceCurrency' => intval($request->input('balance_currency_id')), | ||||
|  | ||||
|         ]; | ||||
|         $account     = $repository->store($accountData); | ||||
|  | ||||
|         Session::flash('success', 'New account "' . $account->name . '" stored!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             // set value so create routine will not overwrite URL: | ||||
| @@ -219,7 +228,7 @@ class AccountController extends Controller | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * @param Account                    $account | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function update(AccountFormRequest $request, AccountRepositoryInterface $repository, Account $account) | ||||
|     { | ||||
| @@ -231,7 +240,7 @@ class AccountController extends Controller | ||||
|             'accountRole'            => $request->input('accountRole'), | ||||
|             'virtualBalance'         => floatval($request->input('virtualBalance')), | ||||
|             'openingBalance'         => floatval($request->input('openingBalance')), | ||||
|             'openingBalanceDate'     => new Carbon($request->input('openingBalanceDate')), | ||||
|             'openingBalanceDate'     => new Carbon((string)$request->input('openingBalanceDate')), | ||||
|             'openingBalanceCurrency' => intval($request->input('balance_currency_id')), | ||||
|             'ccType'                 => $request->input('ccType'), | ||||
|             'ccMonthlyPaymentDate'   => $request->input('ccMonthlyPaymentDate'), | ||||
| @@ -240,12 +249,13 @@ class AccountController extends Controller | ||||
|         $repository->update($account, $accountData); | ||||
|  | ||||
|         Session::flash('success', 'Account "' . $account->name . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             // set value so edit routine will not overwrite URL: | ||||
|             Session::put('accounts.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('accounts.edit', $account->id)->withInput(['return_to_edit' => 1]); | ||||
|             return Redirect::route('accounts.edit', [$account->id])->withInput(['return_to_edit' => 1]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -1,14 +1,17 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers\Auth; | ||||
|  | ||||
| use App; | ||||
| use Auth; | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use Illuminate\Contracts\Auth\Guard; | ||||
| use Illuminate\Contracts\Auth\Registrar; | ||||
| use FireflyIII\Models\Role; | ||||
| use FireflyIII\User; | ||||
| use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Mail\Message; | ||||
| use Mail; | ||||
| use Session; | ||||
| use Twig; | ||||
| use Validator; | ||||
|  | ||||
| /** | ||||
|  * Class AuthController | ||||
| @@ -36,17 +39,11 @@ class AuthController extends Controller | ||||
|     /** | ||||
|      * Create a new authentication controller instance. | ||||
|      * | ||||
|      * @param  \Illuminate\Contracts\Auth\Guard     $auth | ||||
|      * @param  \Illuminate\Contracts\Auth\Registrar $registrar | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      */ | ||||
|     public function __construct(Guard $auth, Registrar $registrar) | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->auth      = $auth; | ||||
|         $this->registrar = $registrar; | ||||
|  | ||||
|         $this->middleware('guest', ['except' => 'getLogout']); | ||||
|     } | ||||
|  | ||||
| @@ -67,11 +64,11 @@ class AuthController extends Controller | ||||
|      * | ||||
|      * @param  Request $request | ||||
|      * | ||||
|      * @return \Illuminate\Http\Response | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function postRegister(Request $request) | ||||
|     { | ||||
|         $validator = $this->registrar->validator($request->all()); | ||||
|         $validator = $this->validator($request->all()); | ||||
|  | ||||
|         if ($validator->fails()) { | ||||
|             $this->throwValidationException( | ||||
| @@ -84,25 +81,71 @@ class AuthController extends Controller | ||||
|         $data             = $request->all(); | ||||
|         $data['password'] = bcrypt($data['password']); | ||||
|  | ||||
|         $this->auth->login($this->registrar->create($data)); | ||||
|         Auth::login($this->create($data)); | ||||
|  | ||||
|         // get the email address | ||||
|         $email = $this->auth->user()->email; | ||||
|         if (Auth::user() instanceof User) { | ||||
|             $email   = Auth::user()->email; | ||||
|             $address = route('index'); | ||||
|             // send email. | ||||
|             Mail::send( | ||||
|                 ['emails.registered-html', 'emails.registered'], ['address' => $address], function (Message $message) use ($email) { | ||||
|                 $message->to($email, $email)->subject('Welcome to Firefly III! '); | ||||
|             } | ||||
|             ); | ||||
|  | ||||
|         // send email. | ||||
|         Mail::send( | ||||
|             'emails.registered', [], function (Message $message) use ($email) { | ||||
|             $message->to($email, $email)->subject('Welcome to Firefly III!'); | ||||
|             // set flash message | ||||
|             Session::flash('success', 'You have registered successfully!'); | ||||
|             Session::flash('gaEventCategory', 'user'); | ||||
|             Session::flash('gaEventAction', 'new-registration'); | ||||
|  | ||||
|             // first user ever? | ||||
|             if (User::count() == 1) { | ||||
|                 $admin = Role::where('name', 'owner')->first(); | ||||
|                 Auth::user()->attachRole($admin); | ||||
|             } | ||||
|  | ||||
|  | ||||
|             return redirect($this->redirectPath()); | ||||
|         } | ||||
|         ); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         App::abort(500, 'Not a user!'); | ||||
|  | ||||
|         // set flash message | ||||
|         Session::flash('success', 'You have registered successfully!'); | ||||
|         Session::flash('gaEventCategory', 'user'); | ||||
|         Session::flash('gaEventAction', 'new-registration'); | ||||
|  | ||||
|  | ||||
|         return redirect($this->redirectPath()); | ||||
|         return redirect('/'); | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get a validator for an incoming registration request. | ||||
|      * | ||||
|      * @param  array $data | ||||
|      * | ||||
|      * @return \Illuminate\Contracts\Validation\Validator | ||||
|      */ | ||||
|     public function validator(array $data) | ||||
|     { | ||||
|         return Validator::make( | ||||
|             $data, [ | ||||
|                      'email'    => 'required|email|max:255|unique:users', | ||||
|                      'password' => 'required|confirmed|min:6', | ||||
|                  ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Create a new user instance after a valid registration. | ||||
|      * | ||||
|      * @param  array $data | ||||
|      * | ||||
|      * @return User | ||||
|      */ | ||||
|     public function create(array $data) | ||||
|     { | ||||
|         return User::create( | ||||
|             [ | ||||
|                 'email'    => $data['email'], | ||||
|                 'password' => $data['password'], | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,6 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers\Auth; | ||||
|  | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use Illuminate\Contracts\Auth\Guard; | ||||
| use Illuminate\Contracts\Auth\PasswordBroker; | ||||
| use Illuminate\Foundation\Auth\ResetsPasswords; | ||||
|  | ||||
| /** | ||||
| @@ -33,15 +31,11 @@ class PasswordController extends Controller | ||||
|     /** | ||||
|      * Create a new password controller instance. | ||||
|      * | ||||
|      * @param  \Illuminate\Contracts\Auth\Guard          $auth | ||||
|      * @param  \Illuminate\Contracts\Auth\PasswordBroker $passwords | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      */ | ||||
|     public function __construct(Guard $auth, PasswordBroker $passwords) | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->auth      = $auth; | ||||
|         $this->passwords = $passwords; | ||||
|  | ||||
|  | ||||
|         $this->middleware('guest'); | ||||
|     } | ||||
|   | ||||
| @@ -1,14 +1,12 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers; | ||||
|  | ||||
| use Config; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\BillFormRequest; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| use Input; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Session; | ||||
| use URL; | ||||
| @@ -23,7 +21,7 @@ class BillController extends Controller | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -33,18 +31,21 @@ class BillController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function create() | ||||
|     { | ||||
|         $periods = Config::get('firefly.periods_to_text'); | ||||
|         $periods  = Config::get('firefly.periods_to_text'); | ||||
|         $subTitle = trans('firefly.create_new_bill'); | ||||
|  | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "create another"). | ||||
|         if (Session::get('bills.create.fromStore') !== true) { | ||||
|             Session::put('bills.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('bills.create.fromStore'); | ||||
|         $subTitle = 'Create new bill'; | ||||
|         Session::flash('gaEventCategory', 'bills'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|  | ||||
|         return view('bills.create', compact('periods', 'subTitle')); | ||||
|     } | ||||
| @@ -52,13 +53,15 @@ class BillController extends Controller | ||||
|     /** | ||||
|      * @param Bill $bill | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function delete(Bill $bill) | ||||
|     { | ||||
|         // put previous url in session | ||||
|         Session::put('bills.delete.url', URL::previous()); | ||||
|         $subTitle = 'Delete "' . e($bill->name) . '"'; | ||||
|         Session::flash('gaEventCategory', 'bills'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|         $subTitle = trans('firefly.delete_bill', ['name' => $bill->name]); | ||||
|  | ||||
|         return view('bills.delete', compact('bill', 'subTitle')); | ||||
|     } | ||||
| @@ -74,6 +77,7 @@ class BillController extends Controller | ||||
|         $repository->destroy($bill); | ||||
|  | ||||
|         Session::flash('success', 'The bill was deleted.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::to(Session::get('bills.delete.url')); | ||||
|  | ||||
| @@ -82,18 +86,20 @@ class BillController extends Controller | ||||
|     /** | ||||
|      * @param Bill $bill | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function edit(Bill $bill) | ||||
|     { | ||||
|         $periods  = Config::get('firefly.periods_to_text'); | ||||
|         $subTitle = 'Edit "' . e($bill->name) . '"'; | ||||
|         $subTitle = trans('firefly.edit_bill', ['name' => $bill->name]); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
|         if (Session::get('bills.edit.fromUpdate') !== true) { | ||||
|             Session::put('bills.edit.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('bills.edit.fromUpdate'); | ||||
|         Session::flash('gaEventCategory', 'bills'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         return view('bills.edit', compact('subTitle', 'periods', 'bill')); | ||||
|     } | ||||
| @@ -138,6 +144,7 @@ class BillController extends Controller | ||||
|  | ||||
|  | ||||
|         Session::flash('success', 'Rescanned everything.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::to(URL::previous()); | ||||
|     } | ||||
| @@ -146,7 +153,7 @@ class BillController extends Controller | ||||
|      * @param BillRepositoryInterface $repository | ||||
|      * @param Bill                    $bill | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function show(BillRepositoryInterface $repository, Bill $bill) | ||||
|     { | ||||
| @@ -162,13 +169,14 @@ class BillController extends Controller | ||||
|      * @param BillFormRequest         $request | ||||
|      * @param BillRepositoryInterface $repository | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function store(BillFormRequest $request, BillRepositoryInterface $repository) | ||||
|     { | ||||
|         $billData = $request->getBillData(); | ||||
|         $bill     = $repository->store($billData); | ||||
|         Session::flash('success', 'Bill "' . e($bill->name) . '" stored.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             // set value so create routine will not overwrite URL: | ||||
| @@ -187,7 +195,7 @@ class BillController extends Controller | ||||
|      * @param BillRepositoryInterface $repository | ||||
|      * @param Bill                    $bill | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function update(BillFormRequest $request, BillRepositoryInterface $repository, Bill $bill) | ||||
|     { | ||||
| @@ -195,12 +203,13 @@ class BillController extends Controller | ||||
|         $bill     = $repository->update($bill, $billData); | ||||
|  | ||||
|         Session::flash('success', 'Bill "' . e($bill->name) . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             // set value so edit routine will not overwrite URL: | ||||
|             Session::put('bills.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('bills.edit', $bill->id)->withInput(['return_to_edit' => 1]); | ||||
|             return Redirect::route('bills.edit', [$bill->id])->withInput(['return_to_edit' => 1]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers; | ||||
|  | ||||
| use Amount; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\BudgetFormRequest; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\LimitRepetition; | ||||
| @@ -19,12 +19,13 @@ use View; | ||||
|  * Class BudgetController | ||||
|  * | ||||
|  * @package FireflyIII\Http\Controllers | ||||
|  * @SuppressWarnings(PHPMD.TooManyMethods) | ||||
|  */ | ||||
| class BudgetController extends Controller | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -45,13 +46,17 @@ class BudgetController extends Controller | ||||
|         $amount          = intval(Input::get('amount')); | ||||
|         $date            = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $limitRepetition = $repository->updateLimitAmount($budget, $date, $amount); | ||||
|         if ($amount == 0) { | ||||
|             $limitRepetition = null; | ||||
|         } | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition ? $limitRepetition->id : 0]); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function create() | ||||
|     { | ||||
| @@ -60,6 +65,8 @@ class BudgetController extends Controller | ||||
|             Session::put('budgets.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('budgets.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'budgets'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|         $subTitle = trans('firefly.create_new_budget'); | ||||
|  | ||||
|         return view('budgets.create', compact('subTitle')); | ||||
| @@ -72,10 +79,12 @@ class BudgetController extends Controller | ||||
|      */ | ||||
|     public function delete(Budget $budget) | ||||
|     { | ||||
|         $subTitle = 'Delete budget' . e($budget->name) . '"'; | ||||
|         $subTitle = trans('firefly.delete_budget', ['name' => $budget->name]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('budgets.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'budgets'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|  | ||||
|         return view('budgets.delete', compact('budget', 'subTitle')); | ||||
|     } | ||||
| @@ -94,6 +103,8 @@ class BudgetController extends Controller | ||||
|  | ||||
|  | ||||
|         Session::flash('success', 'The  budget "' . e($name) . '" was deleted.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|  | ||||
|         return Redirect::to(Session::get('budgets.delete.url')); | ||||
|     } | ||||
| @@ -101,17 +112,19 @@ class BudgetController extends Controller | ||||
|     /** | ||||
|      * @param Budget $budget | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function edit(Budget $budget) | ||||
|     { | ||||
|         $subTitle = 'Edit budget "' . e($budget->name) . '"'; | ||||
|         $subTitle = trans('firefly.edit_budget', ['name' => $budget->name]); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
|         if (Session::get('budgets.edit.fromUpdate') !== true) { | ||||
|             Session::put('budgets.edit.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('budgets.edit.fromUpdate'); | ||||
|         Session::flash('gaEventCategory', 'budgets'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         return view('budgets.edit', compact('budget', 'subTitle')); | ||||
|  | ||||
| @@ -120,13 +133,15 @@ class BudgetController extends Controller | ||||
|     /** | ||||
|      * @param BudgetRepositoryInterface $repository | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function index(BudgetRepositoryInterface $repository) | ||||
|     { | ||||
|         $budgets  = $repository->getActiveBudgets(); | ||||
|         $inactive = $repository->getInactiveBudgets(); | ||||
|  | ||||
|         $spent    = '0'; | ||||
|         $budgeted = '0'; | ||||
|         bcscale(2); | ||||
|         /** | ||||
|          * Do some cleanup: | ||||
|          */ | ||||
| @@ -134,37 +149,43 @@ class BudgetController extends Controller | ||||
|  | ||||
|  | ||||
|         // loop the budgets: | ||||
|         $budgets->each( | ||||
|             function (Budget $budget) use ($repository) { | ||||
|                 $date               = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|                 $end                = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|                 $budget->spent      = $repository->spentInPeriodCorrected($budget, $date, $end); | ||||
|                 $budget->currentRep = $repository->getCurrentRepetition($budget, $date); | ||||
|         /** @var Budget $budget */ | ||||
|         foreach ($budgets as $budget) { | ||||
|             $date               = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|             $end                = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|             $budget->spent      = $repository->spentInPeriodCorrected($budget, $date, $end); | ||||
|             $budget->currentRep = $repository->getCurrentRepetition($budget, $date); | ||||
|             if ($budget->currentRep) { | ||||
|                 $budgeted = bcadd($budgeted, $budget->currentRep->amount); | ||||
|             } | ||||
|             $spent = bcadd($spent, $budget->spent); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         $dateAsString      = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); | ||||
|         $budgetIncomeTotal = Preferences::get('budgetIncomeTotal' . $dateAsString, 1000)->data; | ||||
|         $budgetMaximum     = Preferences::get('budgetMaximum', 1000)->data; | ||||
|         $defaultCurrency   = Amount::getDefaultCurrency(); | ||||
|  | ||||
|         return view( | ||||
|             'budgets.index', compact('budgetMaximum', 'budgetIncomeTotal', 'defaultCurrency', 'inactive', 'budgets', 'spent', 'budgeted') | ||||
|         ); | ||||
|  | ||||
|         $dateAsString  = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); | ||||
|         $spent         = $budgets->sum('spent'); | ||||
|         $amount        = Preferences::get('budgetIncomeTotal' . $dateAsString, 1000)->data; | ||||
|         $overspent     = $spent > $amount; | ||||
|         $spentPCT      = $overspent ? ceil($amount / $spent * 100) : ceil($spent / $amount * 100); | ||||
|         $budgetMax     = Preferences::get('budgetMaximum', 1000); | ||||
|         $budgetMaximum = $budgetMax->data; | ||||
|  | ||||
|         return view('budgets.index', compact('budgetMaximum', 'inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param BudgetRepositoryInterface $repository | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function noBudget(BudgetRepositoryInterface $repository) | ||||
|     { | ||||
|         $start    = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end      = Session::get('end', Carbon::now()->startOfMonth()); | ||||
|         $list     = $repository->getWithoutBudget($start, $end); | ||||
|         $subTitle = 'Transactions without a budget between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y'); | ||||
|         $subTitle = trans( | ||||
|             'firefly.without_budget_between', | ||||
|             ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] | ||||
|         ); | ||||
|  | ||||
|         return view('budgets.noBudget', compact('list', 'subTitle')); | ||||
|     } | ||||
| @@ -177,6 +198,7 @@ class BudgetController extends Controller | ||||
|  | ||||
|         $date = Session::get('start', Carbon::now()->startOfMonth())->format('FY'); | ||||
|         Preferences::set('budgetIncomeTotal' . $date, intval(Input::get('amount'))); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::route('budgets.index'); | ||||
|     } | ||||
| @@ -186,7 +208,7 @@ class BudgetController extends Controller | ||||
|      * @param Budget                    $budget | ||||
|      * @param LimitRepetition           $repetition | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function show(BudgetRepositoryInterface $repository, Budget $budget, LimitRepetition $repetition = null) | ||||
|     { | ||||
| @@ -197,8 +219,15 @@ class BudgetController extends Controller | ||||
|         } | ||||
|  | ||||
|         $journals = $repository->getJournals($budget, $repetition); | ||||
|         $limits   = !is_null($repetition->id) ? [$repetition->budgetLimit] : $repository->getBudgetLimits($budget); | ||||
|         $subTitle = !is_null($repetition->id) ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name); | ||||
|  | ||||
|         if (is_null($repetition->id)) { | ||||
|             $limits   = $repository->getBudgetLimits($budget); | ||||
|             $subTitle = e($budget->name); | ||||
|         } else { | ||||
|             $limits   = [$repetition->budgetLimit]; | ||||
|             $subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]); | ||||
|         } | ||||
|  | ||||
|         $journals->setPath('/budgets/show/' . $budget->id); | ||||
|  | ||||
|         return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle')); | ||||
| @@ -219,6 +248,7 @@ class BudgetController extends Controller | ||||
|         $budget     = $repository->store($budgetData); | ||||
|  | ||||
|         Session::flash('success', 'New budget "' . $budget->name . '" stored!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             // set value so create routine will not overwrite URL: | ||||
| @@ -237,7 +267,7 @@ class BudgetController extends Controller | ||||
|      * @param BudgetRepositoryInterface $repository | ||||
|      * @param Budget                    $budget | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function update(BudgetFormRequest $request, BudgetRepositoryInterface $repository, Budget $budget) | ||||
|     { | ||||
| @@ -249,12 +279,13 @@ class BudgetController extends Controller | ||||
|         $repository->update($budget, $budgetData); | ||||
|  | ||||
|         Session::flash('success', 'Budget "' . $budget->name . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             // set value so edit routine will not overwrite URL: | ||||
|             Session::put('budgets.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('budgets.edit', $budget->id)->withInput(['return_to_edit' => 1]); | ||||
|             return Redirect::route('budgets.edit', [$budget->id])->withInput(['return_to_edit' => 1]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
| @@ -263,7 +294,7 @@ class BudgetController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function updateIncome() | ||||
|     { | ||||
|   | ||||
| @@ -7,6 +7,7 @@ use FireflyIII\Models\Category; | ||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Input; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Session; | ||||
| use URL; | ||||
| @@ -21,7 +22,7 @@ class CategoryController extends Controller | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -31,7 +32,7 @@ class CategoryController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function create() | ||||
|     { | ||||
| @@ -40,7 +41,9 @@ class CategoryController extends Controller | ||||
|             Session::put('categories.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('categories.create.fromStore'); | ||||
|         $subTitle = 'Create a new category'; | ||||
|         Session::flash('gaEventCategory', 'categories'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|         $subTitle = trans('firefly.create_new_category'); | ||||
|  | ||||
|         return view('categories.create', compact('subTitle')); | ||||
|     } | ||||
| @@ -52,10 +55,12 @@ class CategoryController extends Controller | ||||
|      */ | ||||
|     public function delete(Category $category) | ||||
|     { | ||||
|         $subTitle = 'Delete category "' . e($category->name) . '"'; | ||||
|         $subTitle = trans('firefly.delete_category', ['name' => $category->name]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('categories.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'categories'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|  | ||||
|         return view('categories.delete', compact('category', 'subTitle')); | ||||
|     } | ||||
| @@ -73,6 +78,7 @@ class CategoryController extends Controller | ||||
|         $repository->destroy($category); | ||||
|  | ||||
|         Session::flash('success', 'The  category "' . e($name) . '" was deleted.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::to(Session::get('categories.delete.url')); | ||||
|     } | ||||
| @@ -80,17 +86,19 @@ class CategoryController extends Controller | ||||
|     /** | ||||
|      * @param Category $category | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function edit(Category $category) | ||||
|     { | ||||
|         $subTitle = 'Edit category "' . e($category->name) . '"'; | ||||
|         $subTitle = trans('firefly.edit_category', ['name' => $category->name]); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
|         if (Session::get('categories.edit.fromUpdate') !== true) { | ||||
|             Session::put('categories.edit.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('categories.edit.fromUpdate'); | ||||
|         Session::flash('gaEventCategory', 'categories'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         return view('categories.edit', compact('category', 'subTitle')); | ||||
|  | ||||
| @@ -99,7 +107,7 @@ class CategoryController extends Controller | ||||
|     /** | ||||
|      * @param CategoryRepositoryInterface $repository | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function index(CategoryRepositoryInterface $repository) | ||||
|     { | ||||
| @@ -124,7 +132,10 @@ class CategoryController extends Controller | ||||
|         $start    = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end      = Session::get('end', Carbon::now()->startOfMonth()); | ||||
|         $list     = $repository->getWithoutCategory($start, $end); | ||||
|         $subTitle = 'Transactions without a category between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y'); | ||||
|         $subTitle = trans( | ||||
|             'firefly.without_category_between', | ||||
|             ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] | ||||
|         ); | ||||
|  | ||||
|         return view('categories.noCategory', compact('list', 'subTitle')); | ||||
|     } | ||||
| @@ -133,7 +144,7 @@ class CategoryController extends Controller | ||||
|      * @param CategoryRepositoryInterface $repository | ||||
|      * @param Category                    $category | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function show(CategoryRepositoryInterface $repository, Category $category) | ||||
|     { | ||||
| @@ -151,7 +162,7 @@ class CategoryController extends Controller | ||||
|      * @param CategoryFormRequest         $request | ||||
|      * @param CategoryRepositoryInterface $repository | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function store(CategoryFormRequest $request, CategoryRepositoryInterface $repository) | ||||
|     { | ||||
| @@ -162,6 +173,7 @@ class CategoryController extends Controller | ||||
|         $category     = $repository->store($categoryData); | ||||
|  | ||||
|         Session::flash('success', 'New category "' . $category->name . '" stored!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             Session::put('categories.create.fromStore', true); | ||||
| @@ -189,11 +201,12 @@ class CategoryController extends Controller | ||||
|         $repository->update($category, $categoryData); | ||||
|  | ||||
|         Session::flash('success', 'Category "' . $category->name . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             Session::put('categories.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('categories.edit', $category->id); | ||||
|             return Redirect::route('categories.edit', [$category->id]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -6,6 +6,7 @@ use Carbon\Carbon; | ||||
| use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Grumpydictator\Gchart\GChart; | ||||
| use Illuminate\Support\Collection; | ||||
| use Preferences; | ||||
| @@ -26,6 +27,10 @@ class AccountController extends Controller | ||||
|      * @param GChart                     $chart | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * | ||||
|      * @param                            $year | ||||
|      * @param                            $month | ||||
|      * @param bool                       $shared | ||||
|      * | ||||
|      * @return \Symfony\Component\HttpFoundation\Response | ||||
|      */ | ||||
|     public function all(GChart $chart, AccountRepositoryInterface $repository, $year, $month, $shared = false) | ||||
| @@ -33,12 +38,23 @@ class AccountController extends Controller | ||||
|         $start = new Carbon($year . '-' . $month . '-01'); | ||||
|         $end   = clone $start; | ||||
|         $end->endOfMonth(); | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('all'); | ||||
|         $cache->addProperty('accounts'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|  | ||||
|         $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') { | ||||
| @@ -47,6 +63,7 @@ class AccountController extends Controller | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // | ||||
|  | ||||
|         $index = 1; | ||||
|         /** @var Account $account */ | ||||
| @@ -70,8 +87,10 @@ class AccountController extends Controller | ||||
|         } | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -91,6 +110,17 @@ class AccountController extends Controller | ||||
|         $end       = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $accounts  = $repository->getFrontpageAccounts($frontPage); | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('frontpage'); | ||||
|         $cache->addProperty('accounts'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|  | ||||
|         $index = 1; | ||||
|         /** @var Account $account */ | ||||
|         foreach ($accounts as $account) { | ||||
| @@ -113,7 +143,10 @@ class AccountController extends Controller | ||||
|         } | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|  | ||||
|     } | ||||
|  | ||||
| @@ -136,6 +169,17 @@ class AccountController extends Controller | ||||
|         $current = clone $start; | ||||
|         $today   = new Carbon; | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('frontpage'); | ||||
|         $cache->addProperty('single'); | ||||
|         $cache->addProperty($account->id); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         while ($end >= $current) { | ||||
|             $certain = $current < $today; | ||||
|             $chart->addRow(clone $current, Steam::balance($account, $current), $certain); | ||||
| @@ -145,6 +189,9 @@ class AccountController extends Controller | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,11 +4,11 @@ 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 FireflyIII\Support\CacheProperties; | ||||
| use Grumpydictator\Gchart\GChart; | ||||
| use Illuminate\Support\Collection; | ||||
| use Response; | ||||
| @@ -39,6 +39,14 @@ class BillController extends Controller | ||||
|         $chart->addColumn(trans('firefly.minAmount'), 'number'); | ||||
|         $chart->addColumn(trans('firefly.billEntry'), 'number'); | ||||
|  | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty('single'); | ||||
|         $cache->addProperty('bill'); | ||||
|         $cache->addProperty($bill->id); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         // get first transaction or today for start: | ||||
|         $results = $repository->getJournals($bill); | ||||
|         /** @var TransactionJournal $result */ | ||||
| @@ -48,8 +56,10 @@ class BillController extends Controller | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -67,8 +77,20 @@ class BillController extends Controller | ||||
|         $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()); | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('bills'); | ||||
|         $cache->addProperty('frontpage'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $bills  = $repository->getActiveBills(); | ||||
|         $paid   = new Collection; // journals. | ||||
|         $unpaid = new Collection; // bills | ||||
| @@ -134,8 +156,12 @@ class BillController extends Controller | ||||
|  | ||||
|         $chart->addRow(trans('firefly.unpaid') . ': ' . join(', ', $unpaidDescriptions), $unpaidAmount); | ||||
|         $chart->addRow(trans('firefly.paid') . ': ' . join(', ', $paidDescriptions), $paidAmount); | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,6 +7,7 @@ use FireflyIII\Http\Controllers\Controller; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\LimitRepetition; | ||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Grumpydictator\Gchart\GChart; | ||||
| use Illuminate\Support\Collection; | ||||
| use Navigation; | ||||
| @@ -25,6 +26,8 @@ class BudgetController extends Controller | ||||
|      * @param GChart                    $chart | ||||
|      * @param BudgetRepositoryInterface $repository | ||||
|      * @param Budget                    $budget | ||||
|      * | ||||
|      * @return \Symfony\Component\HttpFoundation\Response | ||||
|      */ | ||||
|     public function budget(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget) | ||||
|     { | ||||
| @@ -33,25 +36,47 @@ class BudgetController extends Controller | ||||
|  | ||||
|  | ||||
|         $first = $repository->getFirstBudgetLimitDate($budget); | ||||
|         $range = $viewRange = Preferences::get('viewRange', '1M')->data; | ||||
|         $range = Preferences::get('viewRange', '1M')->data; | ||||
|         $last  = Session::get('end', new Carbon); | ||||
|         $final = clone $last; | ||||
|         $final->addYears(2); | ||||
|         $last = Navigation::endOfX($last, $range, $final); | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($first); | ||||
|         $cache->addProperty($last); | ||||
|         $cache->addProperty('budget'); | ||||
|         $cache->addProperty('budget'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|  | ||||
|         while ($first < $last) { | ||||
|             $end = Navigation::addPeriod($first, $range, 0); | ||||
|             $end->subDay(); | ||||
|  | ||||
|             // start date for chart. | ||||
|             $chartDate = clone $end; | ||||
|             $chartDate->startOfMonth(); | ||||
|  | ||||
|             $spent = $repository->spentInPeriodCorrected($budget, $first, $end); | ||||
|             $chart->addRow($end, $spent); | ||||
|  | ||||
|             $chart->addRow($chartDate, $spent); | ||||
|  | ||||
|             $first = Navigation::addPeriod($first, $range, 0); | ||||
|  | ||||
|  | ||||
|         } | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|  | ||||
|  | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -69,6 +94,18 @@ class BudgetController extends Controller | ||||
|         $start = clone $repetition->startdate; | ||||
|         $end   = $repetition->enddate; | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('budget'); | ||||
|         $cache->addProperty('limit'); | ||||
|         $cache->addProperty($budget->id); | ||||
|         $cache->addProperty($repetition->id); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $chart->addColumn(trans('firefly.day'), 'date'); | ||||
|         $chart->addColumn(trans('firefly.left'), 'number'); | ||||
|  | ||||
| @@ -86,7 +123,10 @@ class BudgetController extends Controller | ||||
|         } | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|  | ||||
|     } | ||||
|  | ||||
| @@ -110,6 +150,18 @@ class BudgetController extends Controller | ||||
|         $end        = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $allEntries = new Collection; | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('budget'); | ||||
|         $cache->addProperty('all'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /** @var Budget $budget */ | ||||
|         foreach ($budgets as $budget) { | ||||
|             $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); | ||||
|             if ($repetitions->count() == 0) { | ||||
| @@ -133,7 +185,7 @@ class BudgetController extends Controller | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); | ||||
|         $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end) * -1; | ||||
|         $allEntries->push([trans('firefly.noBudget'), 0, 0, $noBudgetExpenses]); | ||||
|  | ||||
|         foreach ($allEntries as $entry) { | ||||
| @@ -144,7 +196,10 @@ class BudgetController extends Controller | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|  | ||||
|     } | ||||
|  | ||||
| @@ -165,6 +220,16 @@ class BudgetController extends Controller | ||||
|         $shared  = $shared == 'shared' ? true : false; | ||||
|         $budgets = $repository->getBudgets(); | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('budget'); | ||||
|         $cache->addProperty('year'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         // add columns: | ||||
|         $chart->addColumn(trans('firefly.month'), 'date'); | ||||
|         foreach ($budgets as $budget) { | ||||
| @@ -185,11 +250,14 @@ class BudgetController extends Controller | ||||
|             } | ||||
|             $chart->addRowArray($row); | ||||
|  | ||||
|             $start->addMonth(); | ||||
|             $start->endOfMonth()->addDay(); | ||||
|         } | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,9 +6,8 @@ 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 FireflyIII\Support\CacheProperties; | ||||
| use Grumpydictator\Gchart\GChart; | ||||
| use Navigation; | ||||
| use Preferences; | ||||
| @@ -77,7 +76,18 @@ class CategoryController extends Controller | ||||
|  | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $set   = $repository->getCategoriesAndExpensesCorrected($start, $end); | ||||
|  | ||||
|         // chart properties for cache: | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('category'); | ||||
|         $cache->addProperty('frontpage'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $set = $repository->getCategoriesAndExpensesCorrected($start, $end); | ||||
|  | ||||
|         // sort by callback: | ||||
|         uasort( | ||||
| @@ -101,7 +111,10 @@ class CategoryController extends Controller | ||||
|  | ||||
|         $chart->generate(); | ||||
|  | ||||
|         return Response::json($chart->getData()); | ||||
|         $data = $chart->getData(); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|  | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,19 +1,10 @@ | ||||
| <?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; | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| use Auth; | ||||
| use Config; | ||||
| use Illuminate\Foundation\Bus\DispatchesCommands; | ||||
| use Illuminate\Foundation\Bus\DispatchesJobs; | ||||
| use Illuminate\Foundation\Validation\ValidatesRequests; | ||||
| use Illuminate\Routing\Controller as BaseController; | ||||
| use Preferences; | ||||
| @@ -16,7 +16,7 @@ use View; | ||||
| abstract class Controller extends BaseController | ||||
| { | ||||
|  | ||||
|     use DispatchesCommands, ValidatesRequests; | ||||
|     use DispatchesJobs, ValidatesRequests; | ||||
|  | ||||
|     /** @var string */ | ||||
|     protected $monthAndDayFormat; | ||||
| @@ -24,7 +24,7 @@ abstract class Controller extends BaseController | ||||
|     protected $monthFormat; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|   | ||||
| @@ -1,9 +1,8 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers; | ||||
|  | ||||
| use Auth; | ||||
| use Cache; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\CurrencyFormRequest; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionCurrency; | ||||
| use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | ||||
| use Input; | ||||
| @@ -23,7 +22,7 @@ class CurrencyController extends Controller | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -38,13 +37,15 @@ class CurrencyController extends Controller | ||||
|     public function create() | ||||
|     { | ||||
|         $subTitleIcon = 'fa-plus'; | ||||
|         $subTitle     = 'Create a new currency'; | ||||
|         $subTitle     = trans('firefly.create_currency'); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "create another"). | ||||
|         if (Session::get('currency.create.fromStore') !== true) { | ||||
|             Session::put('currency.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('currency.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'currency'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|  | ||||
|         return view('currency.create', compact('subTitleIcon', 'subTitle')); | ||||
|     } | ||||
| @@ -58,6 +59,7 @@ class CurrencyController extends Controller | ||||
|     { | ||||
|  | ||||
|         Preferences::set('currencyPreference', $currency->code); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         Session::flash('success', $currency->name . ' is now the default currency.'); | ||||
|         Cache::forget('FFCURRENCYSYMBOL'); | ||||
| @@ -84,9 +86,12 @@ class CurrencyController extends Controller | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('currency.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'currency'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|         $subTitle = trans('form.delete_currency', ['name' => $currency->name]); | ||||
|  | ||||
|  | ||||
|         return view('currency.delete', compact('currency')); | ||||
|         return view('currency.delete', compact('currency', 'subTitle')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -105,8 +110,9 @@ class CurrencyController extends Controller | ||||
|         } | ||||
|  | ||||
|         Session::flash('success', 'Currency "' . e($currency->name) . '" deleted'); | ||||
|  | ||||
|         $currency->delete(); | ||||
|         if (Auth::user()->hasRole('owner')) { | ||||
|             $currency->delete(); | ||||
|         } | ||||
|  | ||||
|         return Redirect::to(Session::get('currency.delete.url')); | ||||
|     } | ||||
| @@ -119,7 +125,7 @@ class CurrencyController extends Controller | ||||
|     public function edit(TransactionCurrency $currency) | ||||
|     { | ||||
|         $subTitleIcon     = 'fa-pencil'; | ||||
|         $subTitle         = 'Edit currency "' . e($currency->name) . '"'; | ||||
|         $subTitle         = trans('firefly.edit_currency', ['name' => $currency->name]); | ||||
|         $currency->symbol = htmlentities($currency->symbol); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
| @@ -127,6 +133,8 @@ class CurrencyController extends Controller | ||||
|             Session::put('currency.edit.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('currency.edit.fromUpdate'); | ||||
|         Session::flash('gaEventCategory', 'currency'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         return view('currency.edit', compact('currency', 'subTitle', 'subTitleIcon')); | ||||
|  | ||||
| @@ -142,6 +150,12 @@ class CurrencyController extends Controller | ||||
|         $currencies      = $repository->get(); | ||||
|         $defaultCurrency = $repository->getCurrencyByPreference(Preferences::get('currencyPreference', 'EUR')); | ||||
|  | ||||
|  | ||||
|         if (!Auth::user()->hasRole('owner')) { | ||||
|             Session::flash('warning', 'Please ask ' . env('SITE_OWNER') . ' to add, remove or edit currencies.'); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         return view('currency.index', compact('currencies', 'defaultCurrency')); | ||||
|     } | ||||
|  | ||||
| @@ -154,11 +168,12 @@ class CurrencyController extends Controller | ||||
|      */ | ||||
|     public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository) | ||||
|     { | ||||
|         $data     = $request->getCurrencyData(); | ||||
|         $currency = $repository->store($data); | ||||
|         $data = $request->getCurrencyData(); | ||||
|         if (Auth::user()->hasRole('owner')) { | ||||
|             $currency = $repository->store($data); | ||||
|             Session::flash('success', 'Currency "' . $currency->name . '" created'); | ||||
|  | ||||
|  | ||||
|         Session::flash('success', 'Currency "' . $currency->name . '" created'); | ||||
|         } | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             Session::put('currency.create.fromStore', true); | ||||
| @@ -181,16 +196,18 @@ class CurrencyController extends Controller | ||||
|      */ | ||||
|     public function update(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository, TransactionCurrency $currency) | ||||
|     { | ||||
|         $data     = $request->getCurrencyData(); | ||||
|         $currency = $repository->update($currency, $data); | ||||
|  | ||||
|         $data = $request->getCurrencyData(); | ||||
|         if (Auth::user()->hasRole('owner')) { | ||||
|             $currency = $repository->update($currency, $data); | ||||
|         } | ||||
|         Session::flash('success', 'Currency "' . e($currency->name) . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             Session::put('currency.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('currency.edit', $currency->id); | ||||
|             return Redirect::route('currency.edit', [$currency->id]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use Config; | ||||
| use FireflyIII\Models\Tag; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use Input; | ||||
| use Preferences; | ||||
| @@ -37,6 +38,20 @@ class HomeController extends Controller | ||||
|      */ | ||||
|     public function flush() | ||||
|     { | ||||
|         // get all tags. | ||||
|         // update all counts: | ||||
|         $tags = Tag::get(); | ||||
|  | ||||
|         /** @var Tag $tag */ | ||||
|         foreach ($tags as $tag) { | ||||
|             foreach ($tag->transactionjournals()->get() as $journal) { | ||||
|                 $count              = $journal->tags()->count(); | ||||
|                 $journal->tag_count = $count; | ||||
|                 $journal->save(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         Session::clear(); | ||||
|  | ||||
|         return Redirect::route('index'); | ||||
| @@ -45,30 +60,39 @@ class HomeController extends Controller | ||||
|     /** | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * | ||||
|      * @return \Illuminate\View\View | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View | ||||
|      */ | ||||
|     public function index(AccountRepositoryInterface $repository) | ||||
|     { | ||||
|         $types = Config::get('firefly.accountTypesByIdentifier.asset'); | ||||
|         $count = $repository->countAccounts($types); | ||||
|  | ||||
|  | ||||
|         if ($count == 0) { | ||||
|             return Redirect::route('new-user.index'); | ||||
|         } | ||||
|  | ||||
|         $title         = 'Firefly'; | ||||
|         $subTitle      = trans('firefly.welcomeBack'); | ||||
|         $mainTitleIcon = 'fa-fire'; | ||||
|         $transactions  = []; | ||||
|         $frontPage     = Preferences::get('frontPageAccounts', []); | ||||
|         $start         = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end           = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|         $accounts = $repository->getFrontpageAccounts($frontPage); | ||||
|         $savings  = $repository->getSavingsAccounts(); | ||||
|  | ||||
|         $types             = Config::get('firefly.accountTypesByIdentifier.asset'); | ||||
|         $count             = $repository->countAccounts($types); | ||||
|         $title             = 'Firefly'; | ||||
|         $subTitle          = trans('firefly.welcomeBack'); | ||||
|         $mainTitleIcon     = 'fa-fire'; | ||||
|         $transactions      = []; | ||||
|         $frontPage         = Preferences::get('frontPageAccounts', []); | ||||
|         $start             = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end               = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $accounts          = $repository->getFrontpageAccounts($frontPage); | ||||
|         $savings           = $repository->getSavingsAccounts(); | ||||
|         $piggyBankAccounts = $repository->getPiggyBankAccounts(); | ||||
|  | ||||
|  | ||||
|         $savingsTotal = 0; | ||||
|         foreach ($savings as $savingAccount) { | ||||
|             $savingsTotal += Steam::balance($savingAccount, $end); | ||||
|         } | ||||
|  | ||||
|         $sum = $repository->sumOfEverything(); | ||||
|  | ||||
|         if ($sum != 0) { | ||||
|             Session::flash( | ||||
|                 'error', 'Your transactions are unbalanced. This means a' | ||||
| @@ -79,6 +103,7 @@ class HomeController extends Controller | ||||
|  | ||||
|         foreach ($accounts as $account) { | ||||
|             $set = $repository->getFrontpageTransactions($account, $start, $end); | ||||
|  | ||||
|             if (count($set) > 0) { | ||||
|                 $transactions[] = [$set, $account]; | ||||
|             } | ||||
| @@ -86,6 +111,4 @@ class HomeController extends Controller | ||||
|  | ||||
|         return view('index', compact('count', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -5,12 +5,12 @@ use Carbon\Carbon; | ||||
| use FireflyIII\Helpers\Report\ReportQueryInterface; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\Preference; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\Tag\TagRepositoryInterface; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Support\Collection; | ||||
| use Response; | ||||
| use Session; | ||||
| @@ -34,10 +34,21 @@ class JsonController extends Controller | ||||
|      */ | ||||
|     public function boxBillsPaid(BillRepositoryInterface $repository, AccountRepositoryInterface $accountRepository) | ||||
|     { | ||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|         // works for json too! | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('box-bills-paid'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $amount = 0; | ||||
|  | ||||
|  | ||||
|         // these two functions are the same as the chart | ||||
|         $bills = $repository->getActiveBills(); | ||||
|  | ||||
| @@ -61,8 +72,11 @@ class JsonController extends Controller | ||||
|                 $amount += $accountRepository->getTransfersInRange($creditCard, $start, $end)->sum('amount'); | ||||
|             } | ||||
|         } | ||||
|         $data = ['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json(['box' => 'bills-paid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -76,6 +90,16 @@ class JsonController extends Controller | ||||
|         $amount = 0; | ||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|         // works for json too! | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('box-bills-unpaid'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $bills  = $repository->getActiveBills(); | ||||
|         $unpaid = new Collection; // bills | ||||
|  | ||||
| @@ -110,7 +134,10 @@ class JsonController extends Controller | ||||
|             $amount += $current; | ||||
|         } | ||||
|  | ||||
|         return Response::json(['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||
|         $data = ['box' => 'bills-unpaid', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -120,16 +147,24 @@ class JsonController extends Controller | ||||
|      */ | ||||
|     public function boxIn(ReportQueryInterface $reportQuery) | ||||
|     { | ||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $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; | ||||
|         //        } | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|         return Response::json(['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||
|         // works for json too! | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('box-in'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $amount = $reportQuery->incomeInPeriodCorrected($start, $end, true)->sum('amount'); | ||||
|  | ||||
|         $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -139,11 +174,25 @@ class JsonController extends Controller | ||||
|      */ | ||||
|     public function boxOut(ReportQueryInterface $reportQuery) | ||||
|     { | ||||
|         $start  = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end    = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|         $start = Session::get('start', Carbon::now()->startOfMonth()); | ||||
|         $end   = Session::get('end', Carbon::now()->endOfMonth()); | ||||
|  | ||||
|  | ||||
|         // works for json too! | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         $cache->addProperty('box-out'); | ||||
|         if ($cache->has()) { | ||||
|             return Response::json($cache->get()); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $amount = $reportQuery->expenseInPeriodCorrected($start, $end, true)->sum('amount'); | ||||
|  | ||||
|         return Response::json(['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]); | ||||
|         $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return Response::json($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
							
								
								
									
										111
									
								
								app/Http/Controllers/NewUserController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								app/Http/Controllers/NewUserController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,111 @@ | ||||
| <?php namespace FireflyIII\Http\Controllers; | ||||
|  | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Config; | ||||
| use FireflyIII\Http\Requests\NewUserFormRequest; | ||||
| use FireflyIII\Models\AccountMeta; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Session; | ||||
| use View; | ||||
|  | ||||
| /** | ||||
|  * Class NewUserController | ||||
|  * | ||||
|  * @package FireflyIII\Http\Controllers | ||||
|  */ | ||||
| class NewUserController extends Controller | ||||
| { | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * | ||||
|      * @@return \Illuminate\Http\RedirectResponse|\Illuminate\View\View | ||||
|      */ | ||||
|     public function index(AccountRepositoryInterface $repository) | ||||
|     { | ||||
|         View::share('title', 'Welcome to Firefly!'); | ||||
|         View::share('mainTitleIcon', 'fa-fire'); | ||||
|  | ||||
|  | ||||
|         $types = Config::get('firefly.accountTypesByIdentifier.asset'); | ||||
|         $count = $repository->countAccounts($types); | ||||
|  | ||||
|         if ($count > 0) { | ||||
|             return Redirect::route('index'); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return view('new-user.index'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param NewUserFormRequest         $request | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository) | ||||
|     { | ||||
|  | ||||
|         // create normal asset account: | ||||
|         $assetAccount = [ | ||||
|             'name'                   => $request->get('bank_name'), | ||||
|             'accountType'            => 'asset', | ||||
|             'virtualBalance'         => 0, | ||||
|             'active'                 => true, | ||||
|             'user'                   => Auth::user()->id, | ||||
|             'accountRole'            => 'defaultAsset', | ||||
|             'openingBalance'         => floatval($request->input('bank_balance')), | ||||
|             'openingBalanceDate'     => new Carbon, | ||||
|             'openingBalanceCurrency' => intval($request->input('balance_currency_id')), | ||||
|         ]; | ||||
|  | ||||
|         $repository->store($assetAccount); | ||||
|  | ||||
|         // create savings account | ||||
|         if (strlen($request->get('savings_balance') > 0)) { | ||||
|             $savingsAccount = [ | ||||
|                 'name'                   => $request->get('bank_name') . ' savings account', | ||||
|                 'accountType'            => 'asset', | ||||
|                 'virtualBalance'         => 0, | ||||
|                 'active'                 => true, | ||||
|                 'user'                   => Auth::user()->id, | ||||
|                 'accountRole'            => 'savingAsset', | ||||
|                 'openingBalance'         => floatval($request->input('savings_balance')), | ||||
|                 'openingBalanceDate'     => new Carbon, | ||||
|                 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), | ||||
|             ]; | ||||
|             $repository->store($savingsAccount); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         // create credit card. | ||||
|         if (strlen($request->get('credit_card_limit') > 0)) { | ||||
|             $creditAccount = [ | ||||
|                 'name'                   => 'Credit card', | ||||
|                 'accountType'            => 'asset', | ||||
|                 'virtualBalance'         => floatval($request->get('credit_card_limit')), | ||||
|                 'active'                 => true, | ||||
|                 'user'                   => Auth::user()->id, | ||||
|                 'accountRole'            => 'ccAsset', | ||||
|                 'openingBalance'         => null, | ||||
|                 'openingBalanceDate'     => null, | ||||
|                 'openingBalanceCurrency' => intval($request->input('balance_currency_id')), | ||||
|             ]; | ||||
|             $creditCard    = $repository->store($creditAccount); | ||||
|  | ||||
|             // store meta for CC: | ||||
|             AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id,]); | ||||
|             AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id,]); | ||||
|  | ||||
|         } | ||||
|         Session::flash('success', 'New account(s) created!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::route('index'); | ||||
|     } | ||||
| } | ||||
| @@ -4,13 +4,13 @@ use Amount; | ||||
| use Carbon\Carbon; | ||||
| use Config; | ||||
| use ExpandedForm; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\PiggyBankFormRequest; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Input; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Session; | ||||
| use Steam; | ||||
| @@ -18,6 +18,9 @@ use URL; | ||||
| use View; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * @SuppressWarnings(PHPMD.TooManyMethods) | ||||
|  * | ||||
|  * Class PiggyBankController | ||||
|  * | ||||
|  * @package FireflyIII\Http\Controllers | ||||
| @@ -26,7 +29,7 @@ class PiggyBankController extends Controller | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -64,7 +67,7 @@ class PiggyBankController extends Controller | ||||
|  | ||||
|         $periods      = Config::get('firefly.piggy_bank_periods'); | ||||
|         $accounts     = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||
|         $subTitle     = 'Create new piggy bank'; | ||||
|         $subTitle     = trans('firefly.create_new_piggybank'); | ||||
|         $subTitleIcon = 'fa-plus'; | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "create another"). | ||||
| @@ -72,6 +75,8 @@ class PiggyBankController extends Controller | ||||
|             Session::put('piggy-banks.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('piggy-banks.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'piggy-banks'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|  | ||||
|         return view('piggy-banks.create', compact('accounts', 'periods', 'subTitle', 'subTitleIcon')); | ||||
|     } | ||||
| @@ -83,10 +88,12 @@ class PiggyBankController extends Controller | ||||
|      */ | ||||
|     public function delete(PiggyBank $piggyBank) | ||||
|     { | ||||
|         $subTitle = 'Delete "' . e($piggyBank->name) . '"'; | ||||
|         $subTitle = trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('piggy-banks.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'piggy-banks'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|  | ||||
|         return view('piggy-banks.delete', compact('piggyBank', 'subTitle')); | ||||
|     } | ||||
| @@ -102,6 +109,7 @@ class PiggyBankController extends Controller | ||||
|  | ||||
|  | ||||
|         Session::flash('success', 'Piggy bank "' . e($piggyBank->name) . '" deleted.'); | ||||
|         Preferences::mark(); | ||||
|         $repository->destroy($piggyBank); | ||||
|  | ||||
|         return Redirect::to(Session::get('piggy-banks.delete.url')); | ||||
| @@ -118,7 +126,7 @@ class PiggyBankController extends Controller | ||||
|  | ||||
|         $periods      = Config::get('firefly.piggy_bank_periods'); | ||||
|         $accounts     = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||
|         $subTitle     = 'Edit piggy bank "' . e($piggyBank->name) . '"'; | ||||
|         $subTitle     = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); | ||||
|         $subTitleIcon = 'fa-pencil'; | ||||
|  | ||||
|         /* | ||||
| @@ -138,6 +146,8 @@ class PiggyBankController extends Controller | ||||
|                       'remind_me'    => intval($piggyBank->remind_me) == 1 && !is_null($piggyBank->reminder) ? true : false | ||||
|         ]; | ||||
|         Session::flash('preFilled', $preFilled); | ||||
|         Session::flash('gaEventCategory', 'piggy-banks'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
|         if (Session::get('piggy-banks.edit.fromUpdate') !== true) { | ||||
| @@ -200,6 +210,7 @@ class PiggyBankController extends Controller | ||||
|         // set all users piggy banks to zero: | ||||
|         $repository->reset(); | ||||
|  | ||||
|  | ||||
|         if (is_array($data)) { | ||||
|             foreach ($data as $order => $id) { | ||||
|                 $repository->setOrder(intval($id), (intval($order) + 1)); | ||||
| @@ -231,12 +242,8 @@ class PiggyBankController extends Controller | ||||
|             // create event | ||||
|             $repository->createEvent($piggyBank, $amount); | ||||
|  | ||||
|             /* | ||||
|              * Create event! | ||||
|              */ | ||||
|             //Event::fire('piggy_bank.addMoney', [$piggyBank, $amount]); // new and used. | ||||
|  | ||||
|             Session::flash('success', 'Added ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); | ||||
|             Preferences::mark(); | ||||
|         } else { | ||||
|             Session::flash('error', 'Could not add ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); | ||||
|         } | ||||
| @@ -265,6 +272,7 @@ class PiggyBankController extends Controller | ||||
|             $repository->createEvent($piggyBank, $amount * -1); | ||||
|  | ||||
|             Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); | ||||
|             Preferences::mark(); | ||||
|         } else { | ||||
|             Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); | ||||
|         } | ||||
| @@ -325,6 +333,7 @@ class PiggyBankController extends Controller | ||||
|         $piggyBank = $repository->store($piggyBankData); | ||||
|  | ||||
|         Session::flash('success', 'Stored piggy bank "' . e($piggyBank->name) . '".'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             Session::put('piggy-banks.create.fromStore', true); | ||||
| @@ -359,11 +368,12 @@ class PiggyBankController extends Controller | ||||
|         $piggyBank = $repository->update($piggyBank, $piggyBankData); | ||||
|  | ||||
|         Session::flash('success', 'Updated piggy bank "' . e($piggyBank->name) . '".'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             Session::put('piggy-banks.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('piggy-banks.edit', $piggyBank->id); | ||||
|             return Redirect::route('piggy-banks.edit', [$piggyBank->id]); | ||||
|         } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,7 @@ class PreferencesController extends Controller | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -38,8 +38,7 @@ class PreferencesController extends Controller | ||||
|         $viewRange         = $viewRangePref->data; | ||||
|         $frontPageAccounts = Preferences::get('frontPageAccounts', []); | ||||
|         $budgetMax         = Preferences::get('budgetMaximum', 1000); | ||||
|         $languagePref      = Preferences::get('language', 'en'); | ||||
|         $language          = $languagePref->data; | ||||
|         $language          = Preferences::get('language', 'en')->data; | ||||
|         $budgetMaximum     = $budgetMax->data; | ||||
|  | ||||
|         return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange')); | ||||
| @@ -78,6 +77,7 @@ class PreferencesController extends Controller | ||||
|  | ||||
|  | ||||
|         Session::flash('success', 'Preferences saved!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::route('preferences'); | ||||
|     } | ||||
|   | ||||
| @@ -56,13 +56,13 @@ class ProfileController extends Controller | ||||
|         if (!Hash::check($request->get('current_password'), Auth::user()->password)) { | ||||
|             Session::flash('error', 'Invalid current password!'); | ||||
|  | ||||
|             return Redirect::route('change-password'); | ||||
|             return Redirect::route('profile.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'); | ||||
|             return Redirect::route('profile.change-password'); | ||||
|         } | ||||
|  | ||||
|         // update the user with the new password. | ||||
| @@ -103,12 +103,14 @@ class ProfileController extends Controller | ||||
|         if (!Hash::check($request->get('password'), Auth::user()->password)) { | ||||
|             Session::flash('error', 'Invalid password!'); | ||||
|  | ||||
|             return Redirect::route('delete-account'); | ||||
|             return Redirect::route('profile.delete-account'); | ||||
|         } | ||||
|  | ||||
|         // DELETE! | ||||
|         Auth::user()->delete(); | ||||
|         Session::flush(); | ||||
|         Session::flash('gaEventCategory', 'user'); | ||||
|         Session::flash('gaEventAction', 'delete-account'); | ||||
|  | ||||
|         return Redirect::route('index'); | ||||
|     } | ||||
|   | ||||
| @@ -31,7 +31,7 @@ class ReminderController extends Controller | ||||
|         ]; | ||||
|         Session::flash('_old_input', $data); | ||||
|  | ||||
|         return Redirect::route('transactions.create', 'transfer'); | ||||
|         return Redirect::route('transactions.create', ['transfer']); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -76,15 +76,13 @@ class ReminderController extends Controller | ||||
|      */ | ||||
|     public function show(Reminder $reminder) | ||||
|     { | ||||
|         $title         = 'Reminder'; | ||||
|         $title         = trans('firefly.reminder'); | ||||
|         $mainTitleIcon = 'fa-clock-o'; | ||||
|         if ($reminder->notnow === true) { | ||||
|             $subTitle = 'Dismissed reminder'; | ||||
|             $subTitle = trans('firefly.dismissed_reminder_for_piggy', ['name' => $reminder->remindersable->name]); | ||||
|         } else { | ||||
|             $subTitle = 'Reminder'; | ||||
|             $subTitle = trans('firefly.reminder_for_piggy', ['name' => $reminder->remindersable->name]); | ||||
|         } | ||||
|         $subTitle .= ' for piggy bank "' . $reminder->remindersable->name . '"'; | ||||
|  | ||||
|  | ||||
|         return view('reminders.show', compact('reminder', 'title', 'subTitle', 'mainTitleIcon')); | ||||
|  | ||||
|   | ||||
| @@ -3,10 +3,6 @@ | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Helpers\Report\ReportHelperInterface; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\LimitRepetition; | ||||
| use FireflyIII\Models\Preference; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use Session; | ||||
| use View; | ||||
| @@ -23,6 +19,8 @@ class ReportController extends Controller | ||||
|     protected $helper; | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param ReportHelperInterface $helper | ||||
|      */ | ||||
|     public function __construct(ReportHelperInterface $helper) | ||||
| @@ -72,14 +70,14 @@ class ReportController extends Controller | ||||
|     public function month($year = '2014', $month = '1', $shared = false) | ||||
|     { | ||||
|         $start            = new Carbon($year . '-' . $month . '-01'); | ||||
|         $subTitle         = trans('firefly.reportForMonth', ['date' => $start->formatLocalized($this->monthFormat)]); | ||||
|         $subTitle         = trans('firefly.reportForMonth', ['month' => $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)]); | ||||
|             $subTitle = trans('firefly.reportForMonthShared', ['month' => $start->formatLocalized($this->monthFormat)]); | ||||
|         } | ||||
|  | ||||
|         $end->endOfMonth(); | ||||
| @@ -92,6 +90,10 @@ class ReportController extends Controller | ||||
|         $balance    = $this->helper->getBalanceReport($start, $end, $shared); | ||||
|         $bills      = $this->helper->getBillReport($start, $end, $shared); | ||||
|  | ||||
|         Session::flash('gaEventCategory', 'report'); | ||||
|         Session::flash('gaEventAction', 'month'); | ||||
|         Session::flash('gaEventLabel', $start->format('F Y')); | ||||
|  | ||||
|  | ||||
|         return view( | ||||
|             'reports.month', | ||||
| @@ -135,18 +137,13 @@ class ReportController extends Controller | ||||
|         $incomes  = $this->helper->getIncomeReport($start, $end, $shared); | ||||
|         $expenses = $this->helper->getExpenseReport($start, $end, $shared); | ||||
|  | ||||
|         Session::flash('gaEventCategory', 'report'); | ||||
|         Session::flash('gaEventAction', 'year'); | ||||
|         Session::flash('gaEventLabel', $start->format('Y')); | ||||
|  | ||||
|         return view( | ||||
|             '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. | ||||
|             ) | ||||
|             compact('start', 'shared', 'accounts', 'incomes', 'expenses', 'subTitle', 'subTitleIcon', 'incomeTopLength', 'expenseTopLength') | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -26,7 +26,7 @@ class SearchController extends Controller | ||||
|         if (!is_null(Input::get('q')) && strlen(Input::get('q')) > 0) { | ||||
|             $rawQuery = trim(Input::get('q')); | ||||
|             $words    = explode(' ', $rawQuery); | ||||
|             $subTitle = 'Results for "' . e($rawQuery) . '"'; | ||||
|             $subTitle = trans('firefly.search_results_for', ['query' => $rawQuery]); | ||||
|  | ||||
|             $transactions = $searcher->searchTransactions($words); | ||||
|             $accounts     = $searcher->searchAccounts($words); | ||||
|   | ||||
| @@ -31,8 +31,11 @@ use View; | ||||
|  */ | ||||
| class TagController extends Controller | ||||
| { | ||||
|  | ||||
|     public $tagOptions = []; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -40,12 +43,12 @@ class TagController extends Controller | ||||
|         View::share('title', 'Tags'); | ||||
|         View::share('mainTitleIcon', 'fa-tags'); | ||||
|         View::share('hideTags', true); | ||||
|         $tagOptions = [ | ||||
|         $this->tagOptions = [ | ||||
|             'nothing'        => 'Just a regular tag.', | ||||
|             'balancingAct'   => 'The tag takes at most two transactions; an expense and a transfer. They\'ll balance each other out.', | ||||
|             'advancePayment' => 'The tag accepts one expense and any number of deposits aimed to repay the original expense.', | ||||
|         ]; | ||||
|         View::share('tagOptions', $tagOptions); | ||||
|         View::share('tagOptions', $this->tagOptions); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -53,7 +56,7 @@ class TagController extends Controller | ||||
|      */ | ||||
|     public function create() | ||||
|     { | ||||
|         $subTitle     = 'New tag'; | ||||
|         $subTitle     = trans('firefly.new_tag'); | ||||
|         $subTitleIcon = 'fa-tag'; | ||||
|  | ||||
|         $preFilled = [ | ||||
| @@ -67,6 +70,8 @@ class TagController extends Controller | ||||
|             Session::put('tags.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('tags.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'tags'); | ||||
|         Session::flash('gaEventAction', 'create'); | ||||
|  | ||||
|         return view('tags.create', compact('subTitle', 'subTitleIcon')); | ||||
|     } | ||||
| @@ -78,10 +83,12 @@ class TagController extends Controller | ||||
|      */ | ||||
|     public function delete(Tag $tag) | ||||
|     { | ||||
|         $subTitle = 'Delete "' . e($tag->tag) . '"'; | ||||
|         $subTitle = trans('firefly.delete_tag', ['name' => $tag->tag]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('tags.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'tags'); | ||||
|         Session::flash('gaEventAction', 'delete'); | ||||
|  | ||||
|         return view('tags.delete', compact('tag', 'subTitle')); | ||||
|     } | ||||
| @@ -99,84 +106,36 @@ class TagController extends Controller | ||||
|         $repository->destroy($tag); | ||||
|  | ||||
|         Session::flash('success', 'Tag "' . e($tagName) . '" was deleted.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Redirect::to(route('tags.index')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param Tag $tag | ||||
|      * @param Tag                    $tag | ||||
|      * | ||||
|      * @return View | ||||
|      * @param TagRepositoryInterface $repository | ||||
|      * | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function edit(Tag $tag) | ||||
|     public function edit(Tag $tag, TagRepositoryInterface $repository) | ||||
|     { | ||||
|         $subTitle     = 'Edit tag "' . e($tag->tag) . '"'; | ||||
|         $subTitle     = trans('firefly.edit_tag', ['tag' => $tag->tag]); | ||||
|         $subTitleIcon = 'fa-tag'; | ||||
|  | ||||
|         /* | ||||
|          * Default tag options (again) | ||||
|          */ | ||||
|         $tagOptions = [ | ||||
|             'nothing'        => 'Just a regular tag.', | ||||
|             'balancingAct'   => 'The tag takes at most two transactions; an expense and a transfer. They\'ll balance each other out.', | ||||
|             'advancePayment' => 'The tag accepts one expense and any number of deposits aimed to repay the original expense.', | ||||
|         ]; | ||||
|         $tagOptions = $this->tagOptions; | ||||
|  | ||||
|         /* | ||||
|          * Can this tag become another type? | ||||
|          */ | ||||
|         $allowToAdvancePayment = true; | ||||
|         $allowToBalancingAct   = true; | ||||
|  | ||||
|         /* | ||||
|          * If this tag is a balancing act, and it contains transfers, it cannot be | ||||
|          * changes to an advancePayment. | ||||
|          */ | ||||
|  | ||||
|         if ($tag->tagMode == 'balancingAct' || $tag->tagMode == 'nothing') { | ||||
|             foreach ($tag->transactionjournals as $journal) { | ||||
|                 if ($journal->transactionType->type == 'Transfer') { | ||||
|                     $allowToAdvancePayment = false; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /* | ||||
|          * If this tag contains more than one expenses, it cannot become an advance payment. | ||||
|          */ | ||||
|         $count = 0; | ||||
|         foreach ($tag->transactionjournals as $journal) { | ||||
|             if ($journal->transactionType->type == 'Withdrawal') { | ||||
|                 $count++; | ||||
|             } | ||||
|         } | ||||
|         if ($count > 1) { | ||||
|             $allowToAdvancePayment = false; | ||||
|         } | ||||
|  | ||||
|         /* | ||||
|          * If has more than two transactions already, cannot become a balancing act: | ||||
|          */ | ||||
|         if ($tag->transactionjournals->count() > 2) { | ||||
|             $allowToBalancingAct = false; | ||||
|         } | ||||
|  | ||||
|         /* | ||||
|          * If any transaction is a deposit, cannot become a balancing act. | ||||
|          */ | ||||
|         $count = 0; | ||||
|         foreach ($tag->transactionjournals as $journal) { | ||||
|             if ($journal->transactionType->type == 'Deposit') { | ||||
|                 $count++; | ||||
|             } | ||||
|         } | ||||
|         if ($count > 0) { | ||||
|             $allowToBalancingAct = false; | ||||
|         } | ||||
|  | ||||
|         $allowAdvance        = $repository->tagAllowAdvance($tag); | ||||
|         $allowToBalancingAct = $repository->tagAllowBalancing($tag); | ||||
|  | ||||
|         // edit tag options: | ||||
|         if ($allowToAdvancePayment === false) { | ||||
|         if ($allowAdvance === false) { | ||||
|             unset($tagOptions['advancePayment']); | ||||
|         } | ||||
|         if ($allowToBalancingAct === false) { | ||||
| @@ -189,6 +148,8 @@ class TagController extends Controller | ||||
|             Session::put('tags.edit.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('tags.edit.fromUpdate'); | ||||
|         Session::flash('gaEventCategory', 'tags'); | ||||
|         Session::flash('gaEventAction', 'edit'); | ||||
|  | ||||
|         return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon', 'tagOptions')); | ||||
|     } | ||||
| @@ -204,7 +165,7 @@ class TagController extends Controller | ||||
|         $state = $state == 'true' ? true : false; | ||||
|         Preferences::set('hideTagHelp', $state); | ||||
|  | ||||
|         return Response::json(true); | ||||
|         return Response::json([true]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -217,9 +178,24 @@ class TagController extends Controller | ||||
|         $title          = 'Tags'; | ||||
|         $mainTitleIcon  = 'fa-tags'; | ||||
|         $helpHidden     = $helpHiddenPref->data; | ||||
|         $tags           = Auth::user()->tags()->get(); | ||||
|  | ||||
|         return view('tags.index', compact('title', 'mainTitleIcon', 'helpHidden', 'tags')); | ||||
|         // group years. | ||||
|         $types = ['nothing','balancingAct', 'advancePayment']; | ||||
|  | ||||
|         // loop each types and get the tags, group them by year. | ||||
|         $collection = []; | ||||
|         foreach ($types as $type) { | ||||
|             $tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date','ASC')->get(); | ||||
|             /** @var Tag $tag */ | ||||
|             foreach ($tags as $tag) { | ||||
|                 $year                               = is_null($tag->date) ? trans('firefly.no_year') : $tag->date->year; | ||||
|                 $month                              = is_null($tag->date) ? trans('firefly.no_month') : $tag->date->formatLocalized($this->monthFormat); | ||||
|                 $collection[$type][$year][$month][] = $tag; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         return view('tags.index', compact('title', 'mainTitleIcon','types', 'helpHidden', 'collection')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -232,7 +208,7 @@ class TagController extends Controller | ||||
|         $subTitle     = $tag->tag; | ||||
|         $subTitleIcon = 'fa-tag'; | ||||
|  | ||||
|         return view('tags.show', compact('tag', 'subTitle', 'subTitleIcon')); | ||||
|         return view('tags.show', compact('tag', 'subTitle','types', 'subTitleIcon')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -240,7 +216,7 @@ class TagController extends Controller | ||||
|      * | ||||
|      * @param TagRepositoryInterface $repository | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function store(TagFormRequest $request, TagRepositoryInterface $repository) | ||||
|     { | ||||
| @@ -266,6 +242,7 @@ class TagController extends Controller | ||||
|         $repository->store($data); | ||||
|  | ||||
|         Session::flash('success', 'The tag has been created!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             // set value so create routine will not overwrite URL: | ||||
| @@ -284,7 +261,7 @@ class TagController extends Controller | ||||
|      * @param TagRepositoryInterface $repository | ||||
|      * @param Tag                    $tag | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function update(TagFormRequest $request, TagRepositoryInterface $repository, Tag $tag) | ||||
|     { | ||||
| @@ -308,15 +285,17 @@ class TagController extends Controller | ||||
|             'tagMode'     => $request->get('tagMode'), | ||||
|         ]; | ||||
|  | ||||
|  | ||||
|         $repository->update($tag, $data); | ||||
|  | ||||
|         Session::flash('success', 'Tag "' . e($data['tag']) . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             // set value so edit routine will not overwrite URL: | ||||
|             Session::put('tags.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('tags.edit', $tag->id)->withInput(['return_to_edit' => 1]); | ||||
|             return Redirect::route('tags.edit', [$tag->id])->withInput(['return_to_edit' => 1]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -5,13 +5,13 @@ use Carbon\Carbon; | ||||
| use ExpandedForm; | ||||
| use FireflyIII\Events\JournalCreated; | ||||
| use FireflyIII\Events\JournalSaved; | ||||
| use FireflyIII\Http\Requests; | ||||
| use FireflyIII\Http\Requests\JournalFormRequest; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use Input; | ||||
| use Preferences; | ||||
| use Redirect; | ||||
| use Response; | ||||
| use Session; | ||||
| @@ -26,6 +26,7 @@ use View; | ||||
| class TransactionController extends Controller | ||||
| { | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
| @@ -38,7 +39,7 @@ class TransactionController extends Controller | ||||
|      * @param AccountRepositoryInterface $repository | ||||
|      * @param string                     $what | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function create(AccountRepositoryInterface $repository, $what = 'deposit') | ||||
|     { | ||||
| @@ -61,6 +62,8 @@ class TransactionController extends Controller | ||||
|             Session::put('transactions.create.url', URL::previous()); | ||||
|         } | ||||
|         Session::forget('transactions.create.fromStore'); | ||||
|         Session::flash('gaEventCategory', 'transactions'); | ||||
|         Session::flash('gaEventAction', 'create-' . $what); | ||||
|  | ||||
|         asort($piggies); | ||||
|  | ||||
| @@ -73,17 +76,19 @@ class TransactionController extends Controller | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function delete(TransactionJournal $journal) | ||||
|     { | ||||
|         $type     = strtolower($journal->transactionType->type); | ||||
|         $subTitle = 'Delete ' . e($type) . ' "' . e($journal->description) . '"'; | ||||
|         $what     = strtolower($journal->transactionType->type); | ||||
|         $subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]); | ||||
|  | ||||
|         // put previous url in session | ||||
|         Session::put('transactions.delete.url', URL::previous()); | ||||
|         Session::flash('gaEventCategory', 'transactions'); | ||||
|         Session::flash('gaEventAction', 'delete-' . $what); | ||||
|  | ||||
|         return view('transactions.delete', compact('journal', 'subTitle')); | ||||
|         return view('transactions.delete', compact('journal', 'subTitle', 'what')); | ||||
|  | ||||
|  | ||||
|     } | ||||
| @@ -100,6 +105,8 @@ class TransactionController extends Controller | ||||
|  | ||||
|         $repository->delete($transactionJournal); | ||||
|  | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         // redirect to previous URL: | ||||
|         return Redirect::to(Session::get('transactions.delete.url')); | ||||
|     } | ||||
| @@ -114,15 +121,14 @@ class TransactionController extends Controller | ||||
|      */ | ||||
|     public function edit(AccountRepositoryInterface $repository, TransactionJournal $journal) | ||||
|     { | ||||
|         $what         = strtolower($journal->transactiontype->type); | ||||
|         $accounts     = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||
|         $budgets      = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); | ||||
|         $budgets[0]   = trans('form.noBudget'); | ||||
|         $transactions = $journal->transactions()->orderBy('amount', 'DESC')->get(); | ||||
|         $piggies      = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); | ||||
|         $piggies[0]   = trans('form.noPiggybank'); | ||||
|         $subTitle     = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); | ||||
|         $preFilled    = [ | ||||
|         $what       = strtolower($journal->transactionType->type); | ||||
|         $accounts   = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account'])); | ||||
|         $budgets    = ExpandedForm::makeSelectList(Auth::user()->budgets()->get()); | ||||
|         $budgets[0] = trans('form.noBudget'); | ||||
|         $piggies    = ExpandedForm::makeSelectList(Auth::user()->piggyBanks()->get()); | ||||
|         $piggies[0] = trans('form.noPiggybank'); | ||||
|         $subTitle   = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); | ||||
|         $preFilled  = [ | ||||
|             'date'          => $journal->date->format('Y-m-d'), | ||||
|             'category'      => '', | ||||
|             'budget_id'     => 0, | ||||
| @@ -149,14 +155,30 @@ class TransactionController extends Controller | ||||
|             $preFilled['piggy_bank_id'] = $journal->piggyBankEvents()->orderBy('date', 'DESC')->first()->piggy_bank_id; | ||||
|         } | ||||
|  | ||||
|         $preFilled['amount']          = $journal->actualAmount; | ||||
|         $preFilled['account_id']      = $journal->assetAccount->id; | ||||
|         $preFilled['expense_account'] = $transactions[0]->account->name; | ||||
|         $preFilled['revenue_account'] = $transactions[1]->account->name; | ||||
|         $preFilled['account_from_id'] = $transactions[1]->account->id; | ||||
|         $preFilled['account_to_id']   = $transactions[0]->account->id; | ||||
|         $preFilled['amount'] = $journal->actual_amount; | ||||
|  | ||||
|         if ($journal->transactionType->type == 'Withdrawal') { | ||||
|             $preFilled['account_id']      = $journal->source_account->id; | ||||
|             $preFilled['expense_account'] = $journal->destination_account->name; | ||||
|         } else { | ||||
|             $preFilled['account_id']      = $journal->destination_account->id; | ||||
|             $preFilled['revenue_account'] = $journal->source_account->name; | ||||
|         } | ||||
|  | ||||
|         if ($journal->destination_account->accountType->type == 'Cash account') { | ||||
|             $preFilled['expense_account'] = ''; | ||||
|         } | ||||
|         if ($journal->source_account->accountType->type == 'Cash account') { | ||||
|             $preFilled['revenue_account'] = ''; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         $preFilled['account_from_id'] = $journal->source_account->id; | ||||
|         $preFilled['account_to_id']   = $journal->destination_account->id; | ||||
|  | ||||
|         Session::flash('preFilled', $preFilled); | ||||
|         Session::flash('gaEventCategory', 'transactions'); | ||||
|         Session::flash('gaEventAction', 'edit-' . $what); | ||||
|  | ||||
|         // put previous url in session if not redirect from store (not "return_to_edit"). | ||||
|         if (Session::get('transactions.edit.fromUpdate') !== true) { | ||||
| @@ -172,7 +194,7 @@ class TransactionController extends Controller | ||||
|      * @param JournalRepositoryInterface $repository | ||||
|      * @param                            $what | ||||
|      * | ||||
|      * @return View | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function index(JournalRepositoryInterface $repository, $what) | ||||
|     { | ||||
| @@ -229,8 +251,9 @@ class TransactionController extends Controller | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         return Response::json(true); | ||||
|         return Response::json([true]); | ||||
|  | ||||
|     } | ||||
|  | ||||
| @@ -238,7 +261,7 @@ class TransactionController extends Controller | ||||
|      * @param JournalRepositoryInterface $repository | ||||
|      * @param TransactionJournal         $journal | ||||
|      * | ||||
|      * @return $this | ||||
|      * @return \Illuminate\View\View | ||||
|      */ | ||||
|     public function show(JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||
|     { | ||||
| @@ -248,16 +271,17 @@ class TransactionController extends Controller | ||||
|                 $t->after  = $t->before + $t->amount; | ||||
|             } | ||||
|         ); | ||||
|         $subTitle = trans('firefly.' . $journal->transactiontype->type) . ' "' . e($journal->description) . '"'; | ||||
|         $what     = strtolower($journal->transactionType->type); | ||||
|         $subTitle = trans('firefly.' . $journal->transactionType->type) . ' "' . e($journal->description) . '"'; | ||||
|  | ||||
|         return view('transactions.show', compact('journal', 'subTitle')); | ||||
|         return view('transactions.show', compact('journal', 'subTitle', 'what')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param JournalFormRequest         $request | ||||
|      * @param JournalRepositoryInterface $repository | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function store(JournalFormRequest $request, JournalRepositoryInterface $repository) | ||||
|     { | ||||
| @@ -275,12 +299,13 @@ class TransactionController extends Controller | ||||
|         $repository->deactivateReminder($request->get('reminder_id')); | ||||
|  | ||||
|         Session::flash('success', 'New transaction "' . $journal->description . '" stored!'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('create_another')) === 1) { | ||||
|             // set value so create routine will not overwrite URL: | ||||
|             Session::put('transactions.create.fromStore', true); | ||||
|  | ||||
|             return Redirect::route('transactions.create', $request->input('what'))->withInput(); | ||||
|             return Redirect::route('transactions.create', [$request->input('what')])->withInput(); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
| @@ -294,7 +319,7 @@ class TransactionController extends Controller | ||||
|      * @param JournalRepositoryInterface $repository | ||||
|      * @param TransactionJournal         $journal | ||||
|      * | ||||
|      * @return $this|\Illuminate\Http\RedirectResponse | ||||
|      * @return \Illuminate\Http\RedirectResponse | ||||
|      */ | ||||
|     public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal) | ||||
|     { | ||||
| @@ -306,12 +331,13 @@ class TransactionController extends Controller | ||||
|         // update, get events by date and sort DESC | ||||
|  | ||||
|         Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.'); | ||||
|         Preferences::mark(); | ||||
|  | ||||
|         if (intval(Input::get('return_to_edit')) === 1) { | ||||
|             // set value so edit routine will not overwrite URL: | ||||
|             Session::put('transactions.edit.fromUpdate', true); | ||||
|  | ||||
|             return Redirect::route('transactions.edit', $journal->id)->withInput(['return_to_edit' => 1]); | ||||
|             return Redirect::route('transactions.edit', [$journal->id])->withInput(['return_to_edit' => 1]); | ||||
|         } | ||||
|  | ||||
|         // redirect to previous URL. | ||||
|   | ||||
| @@ -38,7 +38,6 @@ class Kernel extends HttpKernel | ||||
|             'guest'      => 'FireflyIII\Http\Middleware\RedirectIfAuthenticated', | ||||
|             'range'      => 'FireflyIII\Http\Middleware\Range', | ||||
|             'reminders'  => 'FireflyIII\Http\Middleware\Reminders', | ||||
|             'piggybanks' => 'FireflyIII\Http\Middleware\PiggyBanks', | ||||
|  | ||||
|         ]; | ||||
|  | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| <?php namespace FireflyIII\Http\Middleware; | ||||
|  | ||||
| use App; | ||||
| use Carbon\Carbon; | ||||
| use Closure; | ||||
| use Config; | ||||
| use FireflyIII\Models\Preference; | ||||
| use Illuminate\Contracts\Auth\Guard; | ||||
| use Illuminate\Http\Request; | ||||
| use Preferences; | ||||
| @@ -55,6 +55,7 @@ class Authenticate | ||||
|         // if logged in, set user language: | ||||
|         $pref = Preferences::get('language', 'en'); | ||||
|         App::setLocale($pref->data); | ||||
|         Carbon::setLocale($pref->data); | ||||
|  | ||||
|         setlocale(LC_TIME, Config::get('firefly.locales.' . $pref->data)); | ||||
|  | ||||
|   | ||||
| @@ -1,70 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FireflyIII\Http\Middleware; | ||||
|  | ||||
|  | ||||
| use Closure; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\PiggyBankRepetition; | ||||
| use Illuminate\Contracts\Auth\Guard; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
|  * Class PiggyBanks | ||||
|  * | ||||
|  * @package FireflyIII\Http\Middleware | ||||
|  */ | ||||
| class PiggyBanks | ||||
| { | ||||
|     /** | ||||
|      * The Guard implementation. | ||||
|      * | ||||
|      * @var Guard | ||||
|      */ | ||||
|     protected $auth; | ||||
|  | ||||
|     /** | ||||
|      * Create a new filter instance. | ||||
|      * | ||||
|      * @param  Guard $auth | ||||
|      * | ||||
|      */ | ||||
|     public function __construct(Guard $auth) | ||||
|     { | ||||
|         $this->auth = $auth; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Handle an incoming request. | ||||
|      * | ||||
|      * @param  \Illuminate\Http\Request $request | ||||
|      * @param  \Closure                 $next | ||||
|      * | ||||
|      * @return mixed | ||||
|      */ | ||||
|     public function handle(Request $request, Closure $next) | ||||
|     { | ||||
|         if ($this->auth->check() && !$request->isXmlHttpRequest()) { | ||||
|             // get piggy banks without a repetition: | ||||
|             /** @var Collection $set */ | ||||
|             $set = $this->auth->user()->piggybanks() | ||||
|                               ->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id') | ||||
|                               ->whereNull('piggy_bank_repetitions.id') | ||||
|                               ->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']); | ||||
|  | ||||
|             /** @var PiggyBank $partialPiggy */ | ||||
|             foreach ($set as $partialPiggy) { | ||||
|                 $repetition = new PiggyBankRepetition; | ||||
|                 $repetition->piggyBank()->associate($partialPiggy); | ||||
|                 $repetition->startdate     = $partialPiggy->startdate; | ||||
|                 $repetition->targetdate    = $partialPiggy->targetdate; | ||||
|                 $repetition->currentamount = 0; | ||||
|                 $repetition->save(); | ||||
|             } | ||||
|             unset($partialPiggy, $set, $repetition); | ||||
|         } | ||||
|  | ||||
|         return $next($request); | ||||
|     } | ||||
| } | ||||
| @@ -7,6 +7,8 @@ use Carbon\Carbon; | ||||
| use Closure; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\Reminder; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use FireflyIII\User; | ||||
| use Illuminate\Contracts\Auth\Guard; | ||||
| use Illuminate\Http\Request; | ||||
| use View; | ||||
| @@ -46,9 +48,25 @@ class Reminders | ||||
|      */ | ||||
|     public function handle(Request $request, Closure $next) | ||||
|     { | ||||
|         if ($this->auth->check() && !$request->isXmlHttpRequest()) { | ||||
|  | ||||
|  | ||||
|         $user = $this->auth->user(); | ||||
|         if ($this->auth->check() && !$request->isXmlHttpRequest() && $user instanceof User) { | ||||
|             // do reminders stuff. | ||||
|             $piggyBanks = $this->auth->user()->piggyBanks()->where('remind_me', 1)->get(); | ||||
|  | ||||
|             // abuse CacheProperties to find out if we need to do this: | ||||
|             $cache = new CacheProperties; | ||||
|  | ||||
|             $cache->addProperty('reminders'); | ||||
|             if ($cache->has()) { | ||||
|                 $reminders = $cache->get(); | ||||
|                 View::share('reminders', $reminders); | ||||
|  | ||||
|                 return $next($request); | ||||
|             } | ||||
|  | ||||
|             $piggyBanks = $user->piggyBanks()->where('remind_me', 1)->get(); | ||||
|  | ||||
|             /** @var \FireflyIII\Helpers\Reminders\ReminderHelperInterface $helper */ | ||||
|             $helper = App::make('FireflyIII\Helpers\Reminders\ReminderHelperInterface'); | ||||
|  | ||||
| @@ -59,19 +77,17 @@ class Reminders | ||||
|             // delete invalid reminders | ||||
|             // this is a construction SQLITE cannot handle :( | ||||
|             if (env('DB_CONNECTION') != 'sqlite') { | ||||
|                 Reminder::whereUserId($this->auth->user()->id) | ||||
|                         ->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id') | ||||
|                         ->whereNull('piggy_banks.id') | ||||
|                         ->delete(); | ||||
|                 Reminder::whereUserId($user->id)->leftJoin('piggy_banks', 'piggy_banks.id', '=', 'remindersable_id')->whereNull('piggy_banks.id')->delete(); | ||||
|             } | ||||
|  | ||||
|             // get and list active reminders: | ||||
|             $reminders = $this->auth->user()->reminders()->today()->get(); | ||||
|             $reminders = $user->reminders()->today()->get(); | ||||
|             $reminders->each( | ||||
|                 function (Reminder $reminder) use ($helper) { | ||||
|                     $reminder->description = $helper->getReminderText($reminder); | ||||
|                 } | ||||
|             ); | ||||
|             $cache->store($reminders); | ||||
|             View::share('reminders', $reminders); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -48,8 +48,8 @@ class BillFormRequest extends Request | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         $nameRule  = 'required|between:1,255|uniqueObjectForUser:bills,name,name_encrypted'; | ||||
|         $matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match,match_encrypted'; | ||||
|         $nameRule  = 'required|between:1,255|uniqueObjectForUser:bills,name'; | ||||
|         $matchRule = 'required|between:1,255|uniqueObjectForUser:bills,match'; | ||||
|         if (intval(Input::get('id')) > 0) { | ||||
|             $nameRule .= ',' . intval(Input::get('id')); | ||||
|             $matchRule .= ',' . intval(Input::get('id')); | ||||
|   | ||||
| @@ -29,9 +29,9 @@ class BudgetFormRequest extends Request | ||||
|     public function rules() | ||||
|     { | ||||
|  | ||||
|         $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,encrypted'; | ||||
|         $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name'; | ||||
|         if (Budget::find(Input::get('id'))) { | ||||
|             $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,encrypted,' . intval(Input::get('id')); | ||||
|             $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . intval(Input::get('id')); | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|   | ||||
| @@ -29,9 +29,9 @@ class CategoryFormRequest extends Request | ||||
|     public function rules() | ||||
|     { | ||||
|  | ||||
|         $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,encrypted'; | ||||
|         $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name'; | ||||
|         if (Category::find(Input::get('id'))) { | ||||
|             $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,encrypted,' . intval(Input::get('id')); | ||||
|             $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . intval(Input::get('id')); | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| use App; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Exception; | ||||
| @@ -85,7 +86,7 @@ class JournalFormRequest extends Request | ||||
|                 $rules['category']        = 'between:1,255'; | ||||
|                 break; | ||||
|             default: | ||||
|                 throw new Exception('Cannot handle ' . $what); | ||||
|                 App::abort(500, 'Cannot handle ' . $what); | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|   | ||||
							
								
								
									
										37
									
								
								app/Http/Requests/NewUserFormRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/Http/Requests/NewUserFormRequest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| use Auth; | ||||
|  | ||||
| /** | ||||
|  * Class NewUserFormRequest | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @package FireflyIII\Http\Requests | ||||
|  */ | ||||
| class NewUserFormRequest extends Request | ||||
| { | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize() | ||||
|     { | ||||
|         // Only allow logged in users | ||||
|         return Auth::check(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             'bank_name'           => 'required|between:1,200', | ||||
|             'bank_balance'        => 'required|numeric', | ||||
|             'savings_balance'     => 'numeric', | ||||
|             'credit_card_limit'   => 'numeric', | ||||
|             'balance_currency_id' => 'exists:transaction_currencies,id', | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @@ -1,11 +1,4 @@ | ||||
| <?php | ||||
| /** | ||||
|  * Created by PhpStorm. | ||||
|  * User: sander | ||||
|  * Date: 27/04/15 | ||||
|  * Time: 12:50 | ||||
|  */ | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| use Auth; | ||||
| @@ -35,10 +28,10 @@ class TagFormRequest extends Request | ||||
|     public function rules() | ||||
|     { | ||||
|         $idRule  = ''; | ||||
|         $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE'; | ||||
|         $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag'; | ||||
|         if (Tag::find(Input::get('id'))) { | ||||
|             $idRule  = 'belongsToUser:tags'; | ||||
|             $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,TRUE,' . Input::get('id'); | ||||
|             $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,' . Input::get('id'); | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| <?php | ||||
| use Carbon\Carbon; | ||||
| use DaveJamesMiller\Breadcrumbs\Generator; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\Budget; | ||||
| @@ -37,14 +36,14 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'accounts.index', function (Generator $breadcrumbs, $what) { | ||||
|     $breadcrumbs->parent('home'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.' . strtolower(e($what)) . '_accounts'), route('accounts.index', $what)); | ||||
|     $breadcrumbs->push(trans('firefly.' . 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->push(trans('breadcrumbs.new_' . strtolower(e($what)) . '_account'), route('accounts.create', [$what])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -55,13 +54,13 @@ Breadcrumbs::register( | ||||
|  | ||||
|  | ||||
|     $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])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'accounts.delete', function (Generator $breadcrumbs, Account $account) { | ||||
|     $breadcrumbs->parent('accounts.show', $account); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_account', ['name' => e($account->name)]), route('accounts.delete', $account->id)); | ||||
|     $breadcrumbs->push(trans('firefly.delete_account', ['name' => e($account->name)]), route('accounts.delete', [$account->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -71,7 +70,7 @@ Breadcrumbs::register( | ||||
|     $breadcrumbs->parent('accounts.show', $account); | ||||
|     $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); | ||||
|  | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_'.$what.'_account', ['name' => e($account->name)]), route('accounts.edit', $account->id)); | ||||
|     $breadcrumbs->push(trans('firefly.edit_' . $what . '_account', ['name' => e($account->name)]), route('accounts.edit', [$account->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -79,26 +78,26 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'budgets.index', function (Generator $breadcrumbs) { | ||||
|     $breadcrumbs->parent('home'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.budgets'), route('budgets.index')); | ||||
|     $breadcrumbs->push(trans('firefly.budgets'), route('budgets.index')); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'budgets.create', function (Generator $breadcrumbs) { | ||||
|     $breadcrumbs->parent('budgets.index'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.newBudget'), route('budgets.create')); | ||||
|     $breadcrumbs->push(trans('firefly.create_new_budget'), route('budgets.create')); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'budgets.edit', function (Generator $breadcrumbs, Budget $budget) { | ||||
|     $breadcrumbs->parent('budgets.show', $budget); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', $budget->id)); | ||||
|     $breadcrumbs->push(trans('firefly.edit_budget', ['name' => e($budget->name)]), route('budgets.edit', [$budget->id])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'budgets.delete', function (Generator $breadcrumbs, Budget $budget) { | ||||
|     $breadcrumbs->parent('budgets.show', $budget); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', $budget->id)); | ||||
|     $breadcrumbs->push(trans('firefly.delete_budget', ['name' => e($budget->name)]), route('budgets.delete', [$budget->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -112,10 +111,10 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'budgets.show', function (Generator $breadcrumbs, Budget $budget, LimitRepetition $repetition = null) { | ||||
|     $breadcrumbs->parent('budgets.index'); | ||||
|     $breadcrumbs->push(e($budget->name), route('budgets.show', $budget->id)); | ||||
|     $breadcrumbs->push(e($budget->name), route('budgets.show', [$budget->id])); | ||||
|     if (!is_null($repetition) && !is_null($repetition->id)) { | ||||
|         $breadcrumbs->push( | ||||
|             Navigation::periodShow($repetition->startdate, $repetition->budgetlimit->repeat_freq), route('budgets.show', $budget->id, $repetition->id) | ||||
|             Navigation::periodShow($repetition->startdate, $repetition->budgetLimit->repeat_freq), route('budgets.show', [$budget->id, $repetition->id]) | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @@ -125,7 +124,7 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'categories.index', function (Generator $breadcrumbs) { | ||||
|     $breadcrumbs->parent('home'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.categories'), route('categories.index')); | ||||
|     $breadcrumbs->push(trans('firefly.categories'), route('categories.index')); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
| @@ -138,20 +137,20 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'categories.edit', function (Generator $breadcrumbs, Category $category) { | ||||
|     $breadcrumbs->parent('categories.show', $category); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_category', ['name' => e($category->name)]), route('categories.edit', $category->id)); | ||||
|     $breadcrumbs->push(trans('firefly.edit_category', ['name' => e($category->name)]), route('categories.edit', [$category->id])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'categories.delete', function (Generator $breadcrumbs, Category $category) { | ||||
|     $breadcrumbs->parent('categories.show', $category); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_category', ['name' => e($category->name)]), route('categories.delete', $category->id)); | ||||
|     $breadcrumbs->push(trans('firefly.delete_category', ['name' => e($category->name)]), route('categories.delete', [$category->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'categories.show', function (Generator $breadcrumbs, Category $category) { | ||||
|     $breadcrumbs->parent('categories.index'); | ||||
|     $breadcrumbs->push(e($category->name), route('categories.show', $category->id)); | ||||
|     $breadcrumbs->push(e($category->name), route('categories.show', [$category->id])); | ||||
|  | ||||
| } | ||||
| ); | ||||
| @@ -167,20 +166,27 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'currency.index', function (Generator $breadcrumbs) { | ||||
|     $breadcrumbs->parent('home'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.currencies'), route('currency.index')); | ||||
|     $breadcrumbs->push(trans('firefly.currencies'), route('currency.index')); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'currency.create', function (Generator $breadcrumbs) { | ||||
|     $breadcrumbs->parent('currency.index'); | ||||
|     $breadcrumbs->push(trans('firefly.create_currency'), route('currency.create')); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'currency.edit', function (Generator $breadcrumbs, TransactionCurrency $currency) { | ||||
|     $breadcrumbs->parent('currency.index'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', $currency->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_currency', ['name' => e($currency->name)]), route('currency.edit', [$currency->id])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'currency.delete', function (Generator $breadcrumbs, TransactionCurrency $currency) { | ||||
|     $breadcrumbs->parent('currency.index'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', $currency->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_currency', ['name' => e($currency->name)]), route('currency.delete', [$currency->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -202,20 +208,20 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'piggy-banks.edit', function (Generator $breadcrumbs, PiggyBank $piggyBank) { | ||||
|     $breadcrumbs->parent('piggy-banks.show', $piggyBank); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_piggyBank', ['name' => 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( | ||||
|     'piggy-banks.delete', function (Generator $breadcrumbs, PiggyBank $piggyBank) { | ||||
|     $breadcrumbs->parent('piggy-banks.show', $piggyBank); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_piggyBank', ['name' => 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])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'piggy-banks.show', function (Generator $breadcrumbs, PiggyBank $piggyBank) { | ||||
|     $breadcrumbs->parent('piggy-banks.index'); | ||||
|     $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', $piggyBank->id)); | ||||
|     $breadcrumbs->push(e($piggyBank->name), route('piggy-banks.show', [$piggyBank->id])); | ||||
|  | ||||
| } | ||||
| ); | ||||
| @@ -262,20 +268,20 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'bills.edit', function (Generator $breadcrumbs, Bill $bill) { | ||||
|     $breadcrumbs->parent('bills.show', $bill); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_bill', ['name' => 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( | ||||
|     'bills.delete', function (Generator $breadcrumbs, Bill $bill) { | ||||
|     $breadcrumbs->parent('bills.show', $bill); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', $bill->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_bill', ['name' => e($bill->name)]), route('bills.delete', [$bill->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'bills.show', function (Generator $breadcrumbs, Bill $bill) { | ||||
|     $breadcrumbs->parent('bills.index'); | ||||
|     $breadcrumbs->push(e($bill->name), route('bills.show', $bill->id)); | ||||
|     $breadcrumbs->push(e($bill->name), route('bills.show', [$bill->id])); | ||||
|  | ||||
| } | ||||
| ); | ||||
| @@ -293,7 +299,7 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'reminders.show', function (Generator $breadcrumbs, Reminder $reminder) { | ||||
|     $breadcrumbs->parent('reminders.index'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', $reminder->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.reminder', ['id' => e($reminder->id)]), route('reminders.show', [$reminder->id])); | ||||
|  | ||||
| } | ||||
| ); | ||||
| @@ -315,18 +321,20 @@ Breadcrumbs::register( | ||||
|     } else { | ||||
|         $title = trans('breadcrumbs.yearly_report', ['date' => $date->year]); | ||||
|     } | ||||
|     $breadcrumbs->push($title, route('reports.year', $date->year)); | ||||
|     $breadcrumbs->push($title, route('reports.year', [$date->year])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'reports.month', function (Generator $breadcrumbs, Carbon $date, $shared) { | ||||
|     $breadcrumbs->parent('reports.year', $date, $shared); | ||||
|     $language = Preferences::get('language', 'en')->data; | ||||
|     $format   = Config::get('firefly.month.' . $language); | ||||
|  | ||||
|     if ($shared) { | ||||
|         $title = trans('breadcrumbs.monthly_report_shared', ['date' => $date->year]); | ||||
|         $title = trans('breadcrumbs.monthly_report_shared', ['date' => $date->formatLocalized($format)]); | ||||
|     } else { | ||||
|         $title = trans('breadcrumbs.monthly_report', ['date' => $date->year]); | ||||
|         $title = trans('breadcrumbs.monthly_report', ['date' => $date->formatLocalized($format)]); | ||||
|     } | ||||
|  | ||||
|     $breadcrumbs->push($title, route('reports.month', [$date->year, $date->month])); | ||||
| @@ -345,26 +353,26 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'transactions.index', function (Generator $breadcrumbs, $what) { | ||||
|     $breadcrumbs->parent('home'); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', $what)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', [$what])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'transactions.create', function (Generator $breadcrumbs, $what) { | ||||
|     $breadcrumbs->parent('transactions.index', $what); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', $what)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.create_' . e($what)), route('transactions.create', [$what])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| Breadcrumbs::register( | ||||
|     'transactions.edit', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||
|     $breadcrumbs->parent('transactions.show', $journal); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', $journal->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.edit_journal', ['description' => $journal->description]), route('transactions.edit', [$journal->id])); | ||||
| } | ||||
| ); | ||||
| Breadcrumbs::register( | ||||
|     'transactions.delete', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||
|     $breadcrumbs->parent('transactions.show', $journal); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', $journal->id)); | ||||
|     $breadcrumbs->push(trans('breadcrumbs.delete_journal', ['description' => e($journal->description)]), route('transactions.delete', [$journal->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -372,7 +380,7 @@ Breadcrumbs::register( | ||||
|     'transactions.show', function (Generator $breadcrumbs, TransactionJournal $journal) { | ||||
|  | ||||
|     $breadcrumbs->parent('transactions.index', strtolower($journal->transactionType->type)); | ||||
|     $breadcrumbs->push($journal->description, route('transactions.show', $journal->id)); | ||||
|     $breadcrumbs->push($journal->description, route('transactions.show', [$journal->id])); | ||||
|  | ||||
| } | ||||
| ); | ||||
| @@ -395,14 +403,14 @@ Breadcrumbs::register( | ||||
| 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->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->push(trans('breadcrumbs.delete_tag', ['tag' => e($tag->tag)]), route('tags.delete', [$tag->id])); | ||||
| } | ||||
| ); | ||||
|  | ||||
| @@ -410,6 +418,6 @@ Breadcrumbs::register( | ||||
| Breadcrumbs::register( | ||||
|     'tags.show', function (Generator $breadcrumbs, Tag $tag) { | ||||
|     $breadcrumbs->parent('tags.index'); | ||||
|     $breadcrumbs->push(e($tag->tag), route('tags.show', $tag->id)); | ||||
|     $breadcrumbs->push(e($tag->tag), route('tags.show', [$tag->id])); | ||||
| } | ||||
| ); | ||||
|   | ||||
| @@ -13,10 +13,9 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||||
|  | ||||
|  | ||||
| // models | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'account', | ||||
|     function ($value, $route) { | ||||
|     function ($value) { | ||||
|         if (Auth::check()) { | ||||
|             $object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') | ||||
|                              ->where('account_types.editable', 1) | ||||
| @@ -31,9 +30,8 @@ Route::bind( | ||||
|     } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'tj', function ($value, $route) { | ||||
|     'tj', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -45,9 +43,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'currency', function ($value, $route) { | ||||
|     'currency', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = TransactionCurrency::find($value); | ||||
|         if ($object) { | ||||
| @@ -58,9 +55,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'bill', function ($value, $route) { | ||||
|     'bill', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -72,9 +68,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'budget', function ($value, $route) { | ||||
|     'budget', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -86,9 +81,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'reminder', function ($value, $route) { | ||||
|     'reminder', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = Reminder::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -100,9 +94,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'limitrepetition', function ($value, $route) { | ||||
|     'limitrepetition', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = LimitRepetition::where('limit_repetitions.id', $value) | ||||
|                                  ->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') | ||||
| @@ -118,9 +111,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'piggyBank', function ($value, $route) { | ||||
|     'piggyBank', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = PiggyBank::where('piggy_banks.id', $value) | ||||
|                            ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') | ||||
| @@ -135,9 +127,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'category', function ($value, $route) { | ||||
|     'category', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -151,7 +142,7 @@ Route::bind( | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'reminder', function ($value, $route) { | ||||
|     'reminder', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         /** @var \FireflyIII\Models\Reminder $object */ | ||||
|         $object = Reminder::find($value); | ||||
| @@ -166,9 +157,8 @@ Route::bind( | ||||
| } | ||||
| ); | ||||
|  | ||||
| /** @noinspection PhpUnusedParameterInspection */ | ||||
| Route::bind( | ||||
|     'tag', function ($value, $route) { | ||||
|     'tag', function ($value) { | ||||
|     if (Auth::check()) { | ||||
|         $object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first(); | ||||
|         if ($object) { | ||||
| @@ -194,11 +184,12 @@ Route::controllers( | ||||
| ); | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Home Controller | ||||
|  */ | ||||
| Route::group( | ||||
|     ['middleware' => ['auth', 'range', 'reminders', 'piggybanks']], function () { | ||||
|     ['middleware' => ['auth', 'range', 'reminders']], function () { | ||||
|  | ||||
|     /** | ||||
|      * Home Controller | ||||
|      */ | ||||
|     Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); | ||||
|     Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); | ||||
|     Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); | ||||
| @@ -326,6 +317,12 @@ Route::group( | ||||
|     Route::get('/json/box/bills-paid', ['uses' => 'JsonController@boxBillsPaid', 'as' => 'json.box.unpaid']); | ||||
|     Route::get('/json/transaction-journals/{what}', 'JsonController@transactionJournals'); | ||||
|  | ||||
|     /** | ||||
|      * New user Controller | ||||
|      */ | ||||
|     Route::get('/new-user', ['uses' => 'NewUserController@index', 'as' => 'new-user.index']); | ||||
|     Route::post('/new-user/submit', ['uses' => 'NewUserController@submit', 'as' => 'new-user.submit']); | ||||
|  | ||||
|     /** | ||||
|      * Piggy Bank Controller | ||||
|      */ | ||||
| @@ -353,8 +350,8 @@ Route::group( | ||||
|      * Profile Controller | ||||
|      */ | ||||
|     Route::get('/profile', ['uses' => 'ProfileController@index', 'as' => 'profile']); | ||||
|     Route::get('/profile/change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'change-password']); | ||||
|     Route::get('/profile/delete-account', ['uses' => 'ProfileController@deleteAccount', 'as' => 'delete-account']); | ||||
|     Route::get('/profile/change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'profile.change-password']); | ||||
|     Route::get('/profile/delete-account', ['uses' => 'ProfileController@deleteAccount', 'as' => 'profile.delete-account']); | ||||
|     Route::post('/profile/delete-account', ['uses' => 'ProfileController@postDeleteAccount', 'as' => 'delete-account-post']); | ||||
|     Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword', 'as' => 'change-password-post']); | ||||
|  | ||||
| @@ -370,7 +367,6 @@ Route::group( | ||||
|      * Report Controller | ||||
|      */ | ||||
|     Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']); | ||||
|     //Route::get('/reports/{year}', ['uses' => 'ReportController@year', 'as' => 'reports.year'])->where(['year' => '[0-9]{4}']); | ||||
|     Route::get('/reports/{year}/{shared?}', ['uses' => 'ReportController@year', 'as' => 'reports.year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']); | ||||
|     Route::get('/reports/{year}/{month}/{shared?}', ['uses' => 'ReportController@month', 'as' => 'reports.month'])->where( | ||||
|         ['year' => '[0-9]{4}', 'month' => '[0-9]{1,2}', 'shared' => 'shared'] | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| <?php namespace FireflyIII\Models; | ||||
|  | ||||
| use App; | ||||
| use Crypt; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| @@ -12,12 +11,49 @@ use Watson\Validating\ValidatingTrait; | ||||
|  * Class Account | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                        $id | ||||
|  * @property \Carbon\Carbon                                                                 $created_at | ||||
|  * @property \Carbon\Carbon                                                                 $updated_at | ||||
|  * @property \Carbon\Carbon                                                                 $deleted_at | ||||
|  * @property integer                                                                        $user_id | ||||
|  * @property integer                                                                        $account_type_id | ||||
|  * @property string                                                                         $name | ||||
|  * @property boolean                                                                        $active | ||||
|  * @property boolean                                                                        $encrypted | ||||
|  * @property float                                                                          $virtual_balance | ||||
|  * @property string                                                                         $virtual_balance_encrypted | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta | ||||
|  * @property-read \FireflyIII\Models\AccountType                                            $accountType | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[]   $piggyBanks | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Transaction[] $transactions | ||||
|  * @property-read \FireflyIII\User                                                          $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereAccountTypeId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereActive($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereVirtualBalance($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Account whereVirtualBalanceEncrypted($value) | ||||
|  * @method static \FireflyIII\Models\Account accountTypeIn($types) | ||||
|  * @method static \FireflyIII\Models\Account hasMetaValue($name, $value) | ||||
|  * @property boolean                                                                        joinedAccountTypes | ||||
|  * @property mixed                                                                          startBalance | ||||
|  * @property mixed                                                                          endBalance | ||||
|  * @property mixed                                                                          lastActivityDate | ||||
|  * @property mixed                                                                          piggyBalance | ||||
|  * @property mixed                                                                          difference | ||||
|  * @property mixed                                                                          percentage | ||||
|  */ | ||||
| class Account extends Model | ||||
| { | ||||
|     use SoftDeletes, ValidatingTrait; | ||||
|  | ||||
|     protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance']; | ||||
|     protected $hidden   = ['virtual_balance_encrypted', 'encrypted']; | ||||
|     protected $rules | ||||
|                         = [ | ||||
|             'user_id'         => 'required|exists:users,id', | ||||
| @@ -50,12 +86,6 @@ class Account extends Model | ||||
|         } | ||||
|         // create it! | ||||
|         $account = Account::create($fields); | ||||
|         if (is_null($account->id)) { | ||||
|             // could not create account: | ||||
|             App::abort(500, 'Could not create new account with data: ' . json_encode($fields) . ' because ' . json_encode($account->getErrors())); | ||||
|  | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return $account; | ||||
|  | ||||
| @@ -106,7 +136,7 @@ class Account extends Model | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
| @@ -115,7 +145,9 @@ class Account extends Model | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param $fieldName | ||||
|      * @param string $fieldName | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @return string|null | ||||
|      */ | ||||
| @@ -145,9 +177,7 @@ class Account extends Model | ||||
|             return Crypt::decrypt($value); | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         return $value; | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -203,6 +233,16 @@ class Account extends Model | ||||
|         $this->attributes['encrypted'] = true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     public function setVirtualBalanceAttribute($value) | ||||
|     { | ||||
|         $this->attributes['virtual_balance'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
|   | ||||
| @@ -6,8 +6,21 @@ use Watson\Validating\ValidatingTrait; | ||||
| /** | ||||
|  * Class AccountMeta | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                         $id | ||||
|  * @property \Carbon\Carbon                  $created_at | ||||
|  * @property \Carbon\Carbon                  $updated_at | ||||
|  * @property integer                         $account_id | ||||
|  * @property string                          $name | ||||
|  * @property string                          $data | ||||
|  * @property-read \FireflyIII\Models\Account $account | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereAccountId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountMeta whereData($value) | ||||
|  */ | ||||
| class AccountMeta extends Model | ||||
| { | ||||
|   | ||||
| @@ -5,8 +5,19 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class AccountType | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                    $id | ||||
|  * @property \Carbon\Carbon                                                             $created_at | ||||
|  * @property \Carbon\Carbon                                                             $updated_at | ||||
|  * @property string                                                                     $type | ||||
|  * @property boolean                                                                    $editable | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereType($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\AccountType whereEditable($value) | ||||
|  */ | ||||
| class AccountType extends Model | ||||
| { | ||||
|   | ||||
| @@ -4,9 +4,48 @@ use Crypt; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| /** | ||||
|  * Class Bill | ||||
|  * FireflyIII\Models\Bill | ||||
|  * | ||||
|  * @codeCoverageIgnore Class Bill | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property integer                                                                               $user_id | ||||
|  * @property string                                                                                $name | ||||
|  * @property string                                                                                $match | ||||
|  * @property float                                                                                 $amount_min | ||||
|  * @property string                                                                                $amount_min_encrypted | ||||
|  * @property float                                                                                 $amount_max | ||||
|  * @property string                                                                                $amount_max_encrypted | ||||
|  * @property \Carbon\Carbon                                                                        $date | ||||
|  * @property boolean                                                                               $active | ||||
|  * @property boolean                                                                               $automatch | ||||
|  * @property string                                                                                $repeat_freq | ||||
|  * @property integer                                                                               $skip | ||||
|  * @property boolean                                                                               $name_encrypted | ||||
|  * @property boolean                                                                               $match_encrypted | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals | ||||
|  * @property-read \FireflyIII\User                                                                 $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatch($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMin($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMinEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMax($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAmountMaxEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereDate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereActive($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereAutomatch($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereRepeatFreq($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereSkip($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereNameEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Bill whereMatchEncrypted($value) | ||||
|  * @property mixed                                                                                 nextExpectedMatch | ||||
|  * @property mixed                                                                                 lastFoundMatch | ||||
|  */ | ||||
| class Bill extends Model | ||||
| { | ||||
| @@ -14,6 +53,9 @@ class Bill extends Model | ||||
|     protected $fillable | ||||
|         = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; | ||||
|  | ||||
|     protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      */ | ||||
| @@ -34,9 +76,7 @@ class Bill extends Model | ||||
|             return Crypt::decrypt($value); | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         return $value; | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -51,9 +91,23 @@ class Bill extends Model | ||||
|             return Crypt::decrypt($value); | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         return $value; | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setAmountMaxAttribute($value) | ||||
|     { | ||||
|         $this->attributes['amount_max'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setAmountMinAttribute($value) | ||||
|     { | ||||
|         $this->attributes['amount_min'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -7,15 +7,35 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class Budget | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property \Carbon\Carbon                                                                        $deleted_at | ||||
|  * @property string                                                                                $name | ||||
|  * @property integer                                                                               $user_id | ||||
|  * @property boolean                                                                               $active | ||||
|  * @property boolean                                                                               $encrypted | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\BudgetLimit[]        $budgetlimits | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals | ||||
|  * @property-read \FireflyIII\User                                                                 $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereActive($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Budget whereEncrypted($value) | ||||
|  */ | ||||
| class Budget extends Model | ||||
| { | ||||
|  | ||||
|     use SoftDeletes; | ||||
|  | ||||
|     protected $fillable = ['user_id', 'name']; | ||||
|     protected $fillable = ['user_id', 'name', 'active']; | ||||
|     protected $hidden   = ['encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
| @@ -46,9 +66,7 @@ class Budget extends Model | ||||
|             return Crypt::decrypt($value); | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         return $value; | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -5,12 +5,34 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class BudgetLimit | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                            $id | ||||
|  * @property \Carbon\Carbon                                                                     $created_at | ||||
|  * @property \Carbon\Carbon                                                                     $updated_at | ||||
|  * @property integer                                                                            $budget_id | ||||
|  * @property \Carbon\Carbon                                                                     $startdate | ||||
|  * @property float                                                                              $amount | ||||
|  * @property string                                                                             $amount_encrypted | ||||
|  * @property boolean                                                                            $repeats | ||||
|  * @property string                                                                             $repeat_freq | ||||
|  * @property-read \FireflyIII\Models\Budget                                                     $budget | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\LimitRepetition[] $limitrepetitions | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereBudgetId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereStartdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereAmount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereAmountEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereRepeats($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\BudgetLimit whereRepeatFreq($value) | ||||
|  */ | ||||
| class BudgetLimit extends Model | ||||
| { | ||||
|  | ||||
|     protected $hidden = ['amount_encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
| @@ -35,4 +57,12 @@ class BudgetLimit extends Model | ||||
|         return $this->hasMany('FireflyIII\Models\LimitRepetition'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setAmountAttribute($value) | ||||
|     { | ||||
|         $this->attributes['amount'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| <?php namespace FireflyIII\Models; | ||||
|  | ||||
| use App; | ||||
| use Crypt; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| @@ -8,38 +7,38 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class Category | ||||
|  * | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property \Carbon\Carbon                                                                        $deleted_at | ||||
|  * @property string                                                                                $name | ||||
|  * @property integer                                                                               $user_id | ||||
|  * @property boolean                                                                               $encrypted | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals | ||||
|  * @property-read \FireflyIII\User                                                                 $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Category whereEncrypted($value) | ||||
|  * @property mixed                                                                                 spent | ||||
|  * @property mixed                                                                                 lastActivity | ||||
|  */ | ||||
| class Category extends Model | ||||
| { | ||||
|     use SoftDeletes; | ||||
|  | ||||
|     protected $fillable = ['user_id', 'name']; | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
|         return ['created_at', 'updated_at', 'deleted_at']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
|      */ | ||||
|     public function transactionjournals() | ||||
|     { | ||||
|         return $this->belongsToMany('FireflyIII\Models\TransactionJournal', 'category_transaction_journal', 'category_id'); | ||||
|     } | ||||
|     protected $hidden   = ['encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @param array $fields | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      * | ||||
|      * @return Account|null | ||||
|      * @return Category | ||||
|      */ | ||||
|     public static function firstOrCreateEncrypted(array $fields) | ||||
|     { | ||||
| @@ -59,11 +58,6 @@ class Category extends Model | ||||
|         } | ||||
|         // create it! | ||||
|         $category = Category::create($fields); | ||||
|         if (is_null($category->id)) { | ||||
|             // could not create account: | ||||
|             App::abort(500, 'Could not create new category with data: ' . json_encode($fields)); | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return $category; | ||||
|  | ||||
| @@ -71,22 +65,11 @@ class Category extends Model | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public function user() | ||||
|     public function getDates() | ||||
|     { | ||||
|         return $this->belongsTo('FireflyIII\User'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setNameAttribute($value) | ||||
|     { | ||||
|         $this->attributes['name']      = Crypt::encrypt($value); | ||||
|         $this->attributes['encrypted'] = true; | ||||
|         return ['created_at', 'updated_at', 'deleted_at']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -106,4 +89,33 @@ class Category extends Model | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setNameAttribute($value) | ||||
|     { | ||||
|         $this->attributes['name']      = Crypt::encrypt($value); | ||||
|         $this->attributes['encrypted'] = true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
|      */ | ||||
|     public function transactionjournals() | ||||
|     { | ||||
|         return $this->belongsToMany('FireflyIII\Models\TransactionJournal', 'category_transaction_journal', 'category_id'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
|     public function user() | ||||
|     { | ||||
|         return $this->belongsTo('FireflyIII\User'); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -6,8 +6,22 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class Component | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer        $id | ||||
|  * @property \Carbon\Carbon $created_at | ||||
|  * @property \Carbon\Carbon $updated_at | ||||
|  * @property \Carbon\Carbon $deleted_at | ||||
|  * @property string         $name | ||||
|  * @property integer        $user_id | ||||
|  * @property string         $class | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Component whereClass($value) | ||||
|  */ | ||||
| class Component extends Model | ||||
| { | ||||
|   | ||||
| @@ -1,19 +1,36 @@ | ||||
| <?php namespace FireflyIII\Models; | ||||
|  | ||||
| use Auth; | ||||
| use DB; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| /** | ||||
|  * Class LimitRepetition | ||||
|  * | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                             $id | ||||
|  * @property \Carbon\Carbon                      $created_at | ||||
|  * @property \Carbon\Carbon                      $updated_at | ||||
|  * @property integer                             $budget_limit_id | ||||
|  * @property \Carbon\Carbon                      $startdate | ||||
|  * @property \Carbon\Carbon                      $enddate | ||||
|  * @property float                               $amount | ||||
|  * @property string                              $amount_encrypted | ||||
|  * @property-read \FireflyIII\Models\BudgetLimit $budgetLimit | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereBudgetLimitId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereStartdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereEnddate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereAmount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\LimitRepetition whereAmountEncrypted($value) | ||||
|  */ | ||||
| class LimitRepetition extends Model | ||||
| { | ||||
|  | ||||
|     protected $hidden = ['amount_encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
|     public function budgetLimit() | ||||
| @@ -22,7 +39,6 @@ class LimitRepetition extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getDates() | ||||
| @@ -31,24 +47,11 @@ class LimitRepetition extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function spentInRepetition() | ||||
|     public function setAmountAttribute($value) | ||||
|     { | ||||
|         $sum = DB::table('transactions') | ||||
|                  ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') | ||||
|                  ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') | ||||
|                  ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') | ||||
|                  ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') | ||||
|                  ->where('transaction_journals.date', '>=', $this->startdate->format('Y-m-d')) | ||||
|                  ->where('transaction_journals.date', '<=', $this->enddate->format('Y-m-d')) | ||||
|                  ->where('transaction_journals.user_id', Auth::user()->id) | ||||
|                  ->whereNull('transactions.deleted_at') | ||||
|                  ->where('transactions.amount', '>', 0) | ||||
|                  ->where('limit_repetitions.id', '=', $this->id) | ||||
|                  ->sum('transactions.amount'); | ||||
|  | ||||
|         return floatval($sum); | ||||
|         $this->attributes['amount'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
							
								
								
									
										27
									
								
								app/Models/Permission.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								app/Models/Permission.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FireflyIII\Models; | ||||
|  | ||||
| use Zizaco\Entrust\EntrustPermission; | ||||
|  | ||||
| /** | ||||
|  * Class Permission | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer        $id | ||||
|  * @property string         $name | ||||
|  * @property string         $display_name | ||||
|  * @property string         $description | ||||
|  * @property \Carbon\Carbon $created_at | ||||
|  * @property \Carbon\Carbon $updated_at | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.role')[] $roles | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereDisplayName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereDescription($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Permission whereUpdatedAt($value) | ||||
|  */ | ||||
| class Permission extends EntrustPermission | ||||
| { | ||||
| } | ||||
| @@ -7,17 +7,53 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class PiggyBank | ||||
|  * | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                                $id | ||||
|  * @property \Carbon\Carbon                                                                         $created_at | ||||
|  * @property \Carbon\Carbon                                                                         $updated_at | ||||
|  * @property \Carbon\Carbon                                                                         $deleted_at | ||||
|  * @property integer                                                                                $account_id | ||||
|  * @property string                                                                                 $name | ||||
|  * @property float                                                                                  $targetamount | ||||
|  * @property string                                                                                 $targetamount_encrypted | ||||
|  * @property \Carbon\Carbon                                                                         $startdate | ||||
|  * @property \Carbon\Carbon                                                                         $targetdate | ||||
|  * @property string                                                                                 $reminder | ||||
|  * @property integer                                                                                $reminder_skip | ||||
|  * @property boolean                                                                                $remind_me | ||||
|  * @property integer                                                                                $order | ||||
|  * @property boolean                                                                                $encrypted | ||||
|  * @property-read \FireflyIII\Models\Account                                                        $account | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankRepetition[] $piggyBankRepetitions | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankEvent[]      $piggyBankEvents | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Reminder[]            $reminders | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereAccountId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereTargetamount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereTargetamountEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereStartdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereTargetdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereReminder($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereReminderSkip($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereRemindMe($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereOrder($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereEncrypted($value) | ||||
|  * @property PiggyBankRepetition                                                                    currentRep | ||||
|  */ | ||||
| class PiggyBank extends Model | ||||
| { | ||||
|     use SoftDeletes; | ||||
|  | ||||
|     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']; | ||||
|     protected $hidden = ['targetamount_encrypted', 'encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
|     public function account() | ||||
| @@ -45,7 +81,6 @@ class PiggyBank extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
|      */ | ||||
|     public function piggyBankRepetitions() | ||||
| @@ -54,8 +89,7 @@ class PiggyBank extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
| @@ -63,48 +97,6 @@ class PiggyBank extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getRemindMeAttribute($value) | ||||
|     { | ||||
|         return intval($value) == 1; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
|      */ | ||||
|     public function piggyBankEvents() | ||||
|     { | ||||
|         return $this->hasMany('FireflyIII\Models\PiggyBankEvent'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\MorphMany | ||||
|      */ | ||||
|     public function reminders() | ||||
|     { | ||||
|         return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setNameAttribute($value) | ||||
|     { | ||||
|         $this->attributes['name']      = Crypt::encrypt($value); | ||||
|         $this->attributes['encrypted'] = true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
| @@ -117,8 +109,51 @@ class PiggyBank extends Model | ||||
|             return Crypt::decrypt($value); | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         return $value; | ||||
|         // @codeCoverageIgnoreEnd | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
|      * @return boolean | ||||
|      */ | ||||
|     public function getRemindMeAttribute($value) | ||||
|     { | ||||
|         return intval($value) == 1; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
|      */ | ||||
|     public function piggyBankEvents() | ||||
|     { | ||||
|         return $this->hasMany('FireflyIII\Models\PiggyBankEvent'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\MorphMany | ||||
|      */ | ||||
|     public function reminders() | ||||
|     { | ||||
|         return $this->morphMany('FireflyIII\Models\Reminder', 'remindersable'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setNameAttribute($value) | ||||
|     { | ||||
|         $this->attributes['name']      = Crypt::encrypt($value); | ||||
|         $this->attributes['encrypted'] = true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setTargetamountAttribute($value) | ||||
|     { | ||||
|         $this->attributes['targetamount'] = strval(round($value, 2)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -5,13 +5,32 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class PiggyBankEvent | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                    $id | ||||
|  * @property \Carbon\Carbon                             $created_at | ||||
|  * @property \Carbon\Carbon                             $updated_at | ||||
|  * @property integer                                    $piggy_bank_id | ||||
|  * @property integer                                    $transaction_journal_id | ||||
|  * @property \Carbon\Carbon                             $date | ||||
|  * @property float                                      $amount | ||||
|  * @property string                                     $amount_encrypted | ||||
|  * @property-read \FireflyIII\Models\PiggyBank          $piggyBank | ||||
|  * @property-read \FireflyIII\Models\TransactionJournal $transactionJournal | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent wherePiggyBankId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereTransactionJournalId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereDate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereAmount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankEvent whereAmountEncrypted($value) | ||||
|  */ | ||||
| class PiggyBankEvent extends Model | ||||
| { | ||||
|  | ||||
|     protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'amount']; | ||||
|     protected $hidden   = ['amount_encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
| @@ -29,6 +48,14 @@ class PiggyBankEvent extends Model | ||||
|         return $this->belongsTo('FireflyIII\Models\PiggyBank'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setAmountAttribute($value) | ||||
|     { | ||||
|         $this->attributes['amount'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
|   | ||||
| @@ -7,13 +7,33 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class PiggyBankRepetition | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                           $id | ||||
|  * @property \Carbon\Carbon                    $created_at | ||||
|  * @property \Carbon\Carbon                    $updated_at | ||||
|  * @property integer                           $piggy_bank_id | ||||
|  * @property \Carbon\Carbon                    $startdate | ||||
|  * @property \Carbon\Carbon                    $targetdate | ||||
|  * @property float                             $currentamount | ||||
|  * @property string                            $currentamount_encrypted | ||||
|  * @property-read \FireflyIII\Models\PiggyBank $piggyBank | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition wherePiggyBankId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereStartdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereTargetdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereCurrentamount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBankRepetition whereCurrentamountEncrypted($value) | ||||
|  * @method static \FireflyIII\Models\PiggyBankRepetition onDates($start, $target) | ||||
|  * @method static \FireflyIII\Models\PiggyBankRepetition relevantOnDate($date) | ||||
|  */ | ||||
| class PiggyBankRepetition extends Model | ||||
| { | ||||
|  | ||||
|     protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount']; | ||||
|     protected $hidden   = ['currentamount_encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
| @@ -66,4 +86,12 @@ class PiggyBankRepetition extends Model | ||||
|                      ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function setCurrentamountAttribute($value) | ||||
|     { | ||||
|         $this->attributes['currentamount'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,17 +1,36 @@ | ||||
| <?php namespace FireflyIII\Models; | ||||
|  | ||||
| use Crypt; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
|  | ||||
| /** | ||||
|  * Class Preference | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer               $id | ||||
|  * @property \Carbon\Carbon        $created_at | ||||
|  * @property \Carbon\Carbon        $updated_at | ||||
|  * @property integer               $user_id | ||||
|  * @property string                $name | ||||
|  * @property string                $name_encrypted | ||||
|  * @property string                $data | ||||
|  * @property string                $data_encrypted | ||||
|  * @property-read \FireflyIII\User $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereNameEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereData($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Preference whereDataEncrypted($value) | ||||
|  */ | ||||
| class Preference extends Model | ||||
| { | ||||
|  | ||||
|     protected $fillable = ['user_id', 'data', 'name']; | ||||
|     protected $hidden   = ['data_encrypted', 'name_encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
| @@ -20,7 +39,12 @@ class Preference extends Model | ||||
|      */ | ||||
|     public function getDataAttribute($value) | ||||
|     { | ||||
|         return json_decode($value); | ||||
|         if (is_null($this->data_encrypted)) { | ||||
|             return json_decode($value); | ||||
|         } | ||||
|         $data = Crypt::decrypt($this->data_encrypted); | ||||
|  | ||||
|         return json_decode($data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -36,7 +60,8 @@ class Preference extends Model | ||||
|      */ | ||||
|     public function setDataAttribute($value) | ||||
|     { | ||||
|         $this->attributes['data'] = json_encode($value); | ||||
|         $this->attributes['data']           = ''; | ||||
|         $this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -8,16 +8,46 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class Reminder | ||||
|  * | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer               $id | ||||
|  * @property \Carbon\Carbon        $created_at | ||||
|  * @property \Carbon\Carbon        $updated_at | ||||
|  * @property integer               $user_id | ||||
|  * @property \Carbon\Carbon        $startdate | ||||
|  * @property \Carbon\Carbon        $enddate | ||||
|  * @property boolean               $active | ||||
|  * @property boolean               $notnow | ||||
|  * @property integer               $remindersable_id | ||||
|  * @property string                $remindersable_type | ||||
|  * @property string                $metadata | ||||
|  * @property boolean               $encrypted | ||||
|  * @property-read \                $remindersable | ||||
|  * @property-read \FireflyIII\User $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereStartdate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereEnddate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereActive($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereNotnow($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereRemindersableId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereRemindersableType($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereMetadata($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Reminder whereEncrypted($value) | ||||
|  * @method static \FireflyIII\Models\Reminder onDates($start, $end) | ||||
|  * @method static \FireflyIII\Models\Reminder today() | ||||
|  * @property string                description | ||||
|  */ | ||||
| class Reminder extends Model | ||||
| { | ||||
|  | ||||
|  | ||||
|     protected $fillable = ['user_id', 'startdate', 'metadata', 'enddate', 'active', 'notnow', 'remindersable_id', 'remindersable_type',]; | ||||
|     protected $hidden   = ['encrypted']; | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
| @@ -29,7 +59,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getDates() | ||||
| @@ -38,7 +67,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
| @@ -54,7 +82,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      * | ||||
| @@ -66,7 +93,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\MorphTo | ||||
|      */ | ||||
|     public function remindersable() | ||||
| @@ -75,7 +101,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Carbon          $start | ||||
| @@ -89,7 +114,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param EloquentBuilder $query | ||||
|      * | ||||
| @@ -104,7 +128,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param $value | ||||
|      */ | ||||
| @@ -115,7 +138,6 @@ class Reminder extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|      */ | ||||
|     public function user() | ||||
|   | ||||
							
								
								
									
										28
									
								
								app/Models/Role.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								app/Models/Role.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| <?php | ||||
| namespace FireflyIII\Models; | ||||
|  | ||||
|  | ||||
| use Zizaco\Entrust\EntrustRole; | ||||
|  | ||||
| /** | ||||
|  * Class Role | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer        $id | ||||
|  * @property string         $name | ||||
|  * @property string         $display_name | ||||
|  * @property string         $description | ||||
|  * @property \Carbon\Carbon $created_at | ||||
|  * @property \Carbon\Carbon $updated_at | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('auth.model')[] $users | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\Config::get('entrust.permission')[] $perms | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereDisplayName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereDescription($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Role whereUpdatedAt($value) | ||||
|  */ | ||||
| class Role extends EntrustRole | ||||
| { | ||||
| } | ||||
| @@ -2,7 +2,6 @@ | ||||
|  | ||||
| namespace FireflyIII\Models; | ||||
|  | ||||
| use App; | ||||
| use Crypt; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Watson\Validating\ValidatingTrait; | ||||
| @@ -11,6 +10,32 @@ use Watson\Validating\ValidatingTrait; | ||||
|  * Class Tag | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property string                                                                                $deleted_at | ||||
|  * @property integer                                                                               $user_id | ||||
|  * @property string                                                                                $tag | ||||
|  * @property string                                                                                $tagMode | ||||
|  * @property \Carbon\Carbon                                                                        $date | ||||
|  * @property string                                                                                $description | ||||
|  * @property float                                                                                 $latitude | ||||
|  * @property float                                                                                 $longitude | ||||
|  * @property integer                                                                               $zoomLevel | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals | ||||
|  * @property-read \FireflyIII\User                                                                 $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereTag($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereTagMode($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereDate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereDescription($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereLatitude($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereLongitude($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Tag whereZoomLevel($value) | ||||
|  */ | ||||
| class Tag extends Model | ||||
| { | ||||
| @@ -19,7 +44,7 @@ class Tag extends Model | ||||
|     protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode']; | ||||
|     protected $rules | ||||
|                         = [ | ||||
|             'tag'         => 'required|min:1|uniqueObjectForUser:tags,tag,TRUE', | ||||
|             'tag'         => 'required|min:1', | ||||
|             'description' => 'min:1', | ||||
|             'date'        => 'date', | ||||
|             'latitude'    => 'numeric|min:-90|max:90', | ||||
| @@ -57,12 +82,6 @@ class Tag extends Model | ||||
|         $fields['tagMode']     = 'nothing'; | ||||
|         $fields['description'] = isset($fields['description']) && !is_null($fields['description']) ? $fields['description'] : ''; | ||||
|         $tag                   = Tag::create($fields); | ||||
|         if (is_null($tag->id)) { | ||||
|             // could not create account: | ||||
|             App::abort(500, 'Could not create new tag with data: ' . json_encode($fields) . ' because ' . json_encode($tag->getErrors())); | ||||
|  | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return $tag; | ||||
|  | ||||
| @@ -70,13 +89,40 @@ class Tag extends Model | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
|         return ['created_at', 'updated_at', 'date']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Save the model to the database. | ||||
|      * | ||||
|      * @param  array $options | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function save(array $options = []) | ||||
|     { | ||||
|         foreach ($this->transactionjournals()->get() as $journal) { | ||||
|             $count              = $journal->tags()->count(); | ||||
|             $journal->tag_count = $count; | ||||
|             $journal->save(); | ||||
|         } | ||||
|  | ||||
|         return parent::save($options); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
|      */ | ||||
|     public function transactionjournals() | ||||
|     { | ||||
|         return $this->belongsToMany('FireflyIII\Models\TransactionJournal'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
| @@ -86,6 +132,10 @@ class Tag extends Model | ||||
|      */ | ||||
|     public function getDescriptionAttribute($value) | ||||
|     { | ||||
|         if (is_null($value)) { | ||||
|             return $value; | ||||
|         } | ||||
|  | ||||
|         return Crypt::decrypt($value); | ||||
|     } | ||||
|  | ||||
| @@ -121,15 +171,6 @@ class Tag extends Model | ||||
|         $this->attributes['tag'] = Crypt::encrypt($value); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
|      */ | ||||
|     public function transactionjournals() | ||||
|     { | ||||
|         return $this->belongsToMany('FireflyIII\Models\TransactionJournal'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||||
|   | ||||
| @@ -9,13 +9,38 @@ use Watson\Validating\ValidatingTrait; | ||||
| /** | ||||
|  * Class Transaction | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                    $id | ||||
|  * @property \Carbon\Carbon                             $created_at | ||||
|  * @property \Carbon\Carbon                             $updated_at | ||||
|  * @property \Carbon\Carbon                             $deleted_at | ||||
|  * @property integer                                    $account_id | ||||
|  * @property integer                                    $transaction_journal_id | ||||
|  * @property string                                     $description | ||||
|  * @property float                                      $amount | ||||
|  * @property string                                     $amount_encrypted | ||||
|  * @property-read \FireflyIII\Models\Account            $account | ||||
|  * @property-read \FireflyIII\Models\TransactionJournal $transactionJournal | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereAccountId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereTransactionJournalId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereDescription($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereAmount($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\Transaction whereAmountEncrypted($value) | ||||
|  * @method static \FireflyIII\Models\Transaction after($date) | ||||
|  * @method static \FireflyIII\Models\Transaction before($date) | ||||
|  * @property mixed                                      before | ||||
|  * @property mixed                                      after | ||||
|  */ | ||||
| class Transaction extends Model | ||||
| { | ||||
|  | ||||
|     protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount']; | ||||
|     protected $hidden   = ['encrypted']; | ||||
|     protected $rules | ||||
|                         = [ | ||||
|             'account_id'             => 'required|exists:accounts,id', | ||||
| @@ -33,6 +58,24 @@ class Transaction extends Model | ||||
|         return $this->belongsTo('FireflyIII\Models\Account'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $value | ||||
|      * | ||||
|      * @return float|int | ||||
|      */ | ||||
|     public function getAmountAttribute($value) | ||||
|     { | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
|         return ['created_at', 'updated_at', 'deleted_at']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Carbon          $date | ||||
| @@ -56,11 +99,11 @@ class Transaction extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      * @param $value | ||||
|      */ | ||||
|     public function getDates() | ||||
|     public function setAmountAttribute($value) | ||||
|     { | ||||
|         return ['created_at', 'updated_at', 'deleted_at']; | ||||
|         $this->attributes['amount'] = strval(round($value, 2)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -4,11 +4,25 @@ use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Database\Eloquent\SoftDeletes; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * Class TransactionCurrency | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property \Carbon\Carbon                                                                        $deleted_at | ||||
|  * @property string                                                                                $code | ||||
|  * @property string                                                                                $name | ||||
|  * @property string                                                                                $symbol | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionJournals | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereCode($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereName($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionCurrency whereSymbol($value) | ||||
|  */ | ||||
| class TransactionCurrency extends Model | ||||
| { | ||||
|   | ||||
| @@ -6,8 +6,22 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class TransactionGroup | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property \Carbon\Carbon                                                                        $deleted_at | ||||
|  * @property integer                                                                               $user_id | ||||
|  * @property string                                                                                $relation | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals | ||||
|  * @property-read \FireflyIII\User                                                                 $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionGroup whereRelation($value) | ||||
|  */ | ||||
| class TransactionGroup extends Model | ||||
| { | ||||
|   | ||||
| @@ -2,26 +2,89 @@ | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use Crypt; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Database\Eloquent\Relations\HasMany; | ||||
| use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| use Illuminate\Database\Query\JoinClause; | ||||
| use Watson\Validating\ValidatingTrait; | ||||
|  | ||||
| /** | ||||
|  * Class TransactionJournal | ||||
|  * | ||||
|  * @package FireflyIII\Models | ||||
|  * @SuppressWarnings (PHPMD.TooManyMethods) | ||||
|  * @property integer                                                                             $id | ||||
|  * @property \Carbon\Carbon                                                                      $created_at | ||||
|  * @property \Carbon\Carbon                                                                      $updated_at | ||||
|  * @property \Carbon\Carbon                                                                      $deleted_at | ||||
|  * @property integer                                                                             $user_id | ||||
|  * @property integer                                                                             $transaction_type_id | ||||
|  * @property integer                                                                             $bill_id | ||||
|  * @property integer                                                                             $transaction_currency_id | ||||
|  * @property string                                                                              $description | ||||
|  * @property boolean                                                                             $completed | ||||
|  * @property \Carbon\Carbon                                                                      $date | ||||
|  * @property boolean                                                                             $encrypted | ||||
|  * @property integer                                                                             $order | ||||
|  * @property-read \FireflyIII\Models\Bill                                                        $bill | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Budget[]           $budgets | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[]         $categories | ||||
|  * @property-read mixed                                                                          $actual_amount | ||||
|  * @property-read mixed                                                                          $amount | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Tag[]              $tags | ||||
|  * @property-read mixed                                                                          $asset_account | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Transaction[]      $transactions | ||||
|  * @property-read mixed                                                                          $corrected_actual_amount | ||||
|  * @property-read mixed                                                                          $destination_account | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankEvent[]   $piggyBankEvents | ||||
|  * @property-read \FireflyIII\Models\TransactionCurrency                                         $transactionCurrency | ||||
|  * @property-read \FireflyIII\Models\TransactionType                                             $transactionType | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionGroup[] $transactiongroups | ||||
|  * @property-read \FireflyIII\User                                                               $user | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereUserId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereTransactionTypeId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereBillId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereTransactionCurrencyId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereDescription($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereCompleted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereDate($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereEncrypted($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereOrder($value) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal accountIs($account) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal after($date) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal before($date) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal onDate($date) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal transactionTypes($types) | ||||
|  * @method static \FireflyIII\Models\TransactionJournal withRelevantData() | ||||
|  * @property-read mixed                                                                          $expense_account | ||||
|  * @property string                                                                              account_encrypted | ||||
|  * @property bool                                                                                joinedTransactions | ||||
|  * @property bool                                                                                joinedTransactionTypes | ||||
|  * @property mixed                                                                               account_id | ||||
|  * @property mixed                                                                               name | ||||
|  * @property mixed                                                                               symbol | ||||
|  * @property-read mixed                                                                          $correct_amount | ||||
|  * @method static \FireflyIII\Models\TransactionJournal orderBy | ||||
|  * @method static \FireflyIII\Models\TransactionJournal|null first | ||||
|  * @property-read mixed                                                                          $source_account | ||||
|  * @property integer                                                                             $tag_count | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal whereTagCount($value) | ||||
|  */ | ||||
| class TransactionJournal extends Model | ||||
| { | ||||
|     use SoftDeletes, ValidatingTrait; | ||||
|  | ||||
|     protected $fillable = ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted']; | ||||
|  | ||||
|     protected $fillable | ||||
|                       = ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted', 'tag_count']; | ||||
|     protected $hidden = ['encrypted']; | ||||
|     protected $rules | ||||
|         = [ | ||||
|                       = [ | ||||
|             'user_id'                 => 'required|exists:users,id', | ||||
|             'transaction_type_id'     => 'required|exists:transaction_types,id', | ||||
|             'bill_id'                 => 'exists:bills,id', | ||||
| @@ -60,15 +123,15 @@ class TransactionJournal extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getActualAmountAttribute() | ||||
|     { | ||||
|         $amount = 0; | ||||
|         $amount = '0'; | ||||
|         /** @var Transaction $t */ | ||||
|         foreach ($this->transactions as $t) { | ||||
|             if ($t->amount > 0) { | ||||
|                 $amount = floatval($t->amount); | ||||
|                 $amount = $t->amount; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -80,52 +143,67 @@ class TransactionJournal extends Model | ||||
|      */ | ||||
|     public function getAmountAttribute() | ||||
|     { | ||||
|         $amount = 0; | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($this->id); | ||||
|         $cache->addProperty('amount'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $amount = '0'; | ||||
|         bcscale(2); | ||||
|         /** @var Transaction $t */ | ||||
|         foreach ($this->transactions as $t) { | ||||
|             if ($t->amount > 0) { | ||||
|                 $amount = floatval($t->amount); | ||||
|                 $amount = $t->amount; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /* | ||||
|          * If the journal has tags, it gets complicated. | ||||
|          */ | ||||
|         if ($this->tags->count() == 0) { | ||||
|             return $amount; | ||||
|         } | ||||
|         // if journal is part of advancePayment AND journal is a withdrawal, | ||||
|         // then journal is being repaid by other journals, so the actual amount will lower: | ||||
|         /** @var Tag $advancePayment */ | ||||
|         $advancePayment = $this->tags()->where('tagMode', 'advancePayment')->first(); | ||||
|         if ($advancePayment && $this->transactionType->type == 'Withdrawal') { | ||||
|  | ||||
|             // loop other deposits, remove from our amount. | ||||
|             $others = $advancePayment->transactionJournals()->transactionTypes(['Deposit'])->get(); | ||||
|             foreach ($others as $other) { | ||||
|                 $amount -= $other->actualAmount; | ||||
|             } | ||||
|  | ||||
|             return $amount; | ||||
|         if ($this->tag_count === 1) { | ||||
|             // get amount for single tag: | ||||
|             $amount = $this->amountByTag($this->tags()->first(), $amount); | ||||
|         } | ||||
|  | ||||
|         // if this journal is part of an advancePayment AND the journal is a deposit, | ||||
|         // then the journal amount is correcting a withdrawal, and the amount is zero: | ||||
|         if ($advancePayment && $this->transactionType->type == 'Deposit') { | ||||
|             return 0; | ||||
|         if ($this->tag_count > 1) { | ||||
|             // get amount for either tag. | ||||
|             $amount = $this->amountByTags($amount); | ||||
|  | ||||
|         } | ||||
|         $cache->store($amount); | ||||
|  | ||||
|         return $amount; | ||||
|  | ||||
|         // is balancing act? | ||||
|         $balancingAct = $this->tags()->where('tagMode', 'balancingAct')->first(); | ||||
|         if ($balancingAct) { | ||||
|             // this is the transfer | ||||
|     } | ||||
|  | ||||
|             // this is the expense: | ||||
|     /** | ||||
|      * Assuming the journal has only one tag. Parameter amount is used as fallback. | ||||
|      * | ||||
|      * @param Tag    $tag | ||||
|      * @param string $amount | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     protected function amountByTag(Tag $tag, $amount) | ||||
|     { | ||||
|         if ($tag->tagMode == 'advancePayment') { | ||||
|             if ($this->transactionType->type == 'Withdrawal') { | ||||
|                 $transfer = $balancingAct->transactionJournals()->transactionTypes(['Transfer'])->first(); | ||||
|                 $others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get(); | ||||
|                 foreach ($others as $other) { | ||||
|                     $amount = bcsub($amount, $other->actual_amount); | ||||
|                 } | ||||
|  | ||||
|                 return $amount; | ||||
|             } | ||||
|             if ($this->transactionType->type == 'Deposit') { | ||||
|                 return '0'; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($tag->tagMode == 'balancingAct') { | ||||
|             if ($this->transactionType->type == 'Withdrawal') { | ||||
|                 $transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first(); | ||||
|                 if ($transfer) { | ||||
|                     $amount -= $transfer->actualAmount; | ||||
|                     $amount = bcsub($amount, $transfer->actual_amount); | ||||
|  | ||||
|                     return $amount; | ||||
|                 } | ||||
| @@ -133,6 +211,7 @@ class TransactionJournal extends Model | ||||
|         } | ||||
|  | ||||
|         return $amount; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -145,26 +224,39 @@ class TransactionJournal extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return Account | ||||
|      * @param string $amount | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getAssetAccountAttribute() | ||||
|     public function amountByTags($amount) | ||||
|     { | ||||
|         $positive = true; // the asset account is in the transaction with the positive amount. | ||||
|         if ($this->transactionType->type === 'Withdrawal') { | ||||
|             $positive = false; | ||||
|         } | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($this->transactions()->get() as $transaction) { | ||||
|             if (floatval($transaction->amount) > 0 && $positive === true) { | ||||
|                 return $transaction->account; | ||||
|             } | ||||
|             if (floatval($transaction->amount) < 0 && $positive === false) { | ||||
|                 return $transaction->account; | ||||
|             } | ||||
|  | ||||
|         $firstBalancingAct = $this->tags()->where('tagMode', 'balancingAct')->first(); | ||||
|         if ($firstBalancingAct) { | ||||
|             return $this->amountByTag($firstBalancingAct, $amount); | ||||
|         } | ||||
|  | ||||
|         return $this->transactions()->first()->account; | ||||
|         $firstAdvancePayment = $this->tags()->where('tagMode', 'advancePayment')->first(); | ||||
|         if ($firstAdvancePayment) { | ||||
|             return $this->amountByTag($firstAdvancePayment, $amount); | ||||
|         } | ||||
|  | ||||
|         return $amount; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getCorrectAmountAttribute() | ||||
|     { | ||||
|  | ||||
|         switch ($this->transactionType->type) { | ||||
|             case 'Deposit': | ||||
|                 return $this->transactions()->where('amount', '>', 0)->first()->amount; | ||||
|             case 'Withdrawal': | ||||
|                 return $this->transactions()->where('amount', '<', 0)->first()->amount; | ||||
|         } | ||||
|  | ||||
|         return $this->transactions()->where('amount', '>', 0)->first()->amount; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -176,37 +268,30 @@ class TransactionJournal extends Model | ||||
|         return $this->hasMany('FireflyIII\Models\Transaction'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return float | ||||
|      */ | ||||
|     public function getCorrectedActualAmountAttribute() | ||||
|     { | ||||
|         $amount = 0; | ||||
|         $type   = $this->transactionType->type; | ||||
|         /** @var Transaction $t */ | ||||
|         foreach ($this->transactions as $t) { | ||||
|             if ($t->amount > 0 && $type != 'Withdrawal') { | ||||
|                 $amount = floatval($t->amount); | ||||
|                 break; | ||||
|             } | ||||
|             if ($t->amount < 0 && $type == 'Withdrawal') { | ||||
|                 $amount = floatval($t->amount); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $amount; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return array | ||||
|      * @return string[] | ||||
|      */ | ||||
|     public function getDates() | ||||
|     { | ||||
|         return ['created_at', 'updated_at', 'date', 'deleted_at']; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Save the model to the database. | ||||
|      * | ||||
|      * @param  array $options | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function save(array $options = []) | ||||
|     { | ||||
|         $count           = $this->tags()->count(); | ||||
|         $this->tag_count = $count; | ||||
|  | ||||
|         return parent::save($options); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
| @@ -223,6 +308,42 @@ class TransactionJournal extends Model | ||||
|         return $value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return Account | ||||
|      */ | ||||
|     public function getDestinationAccountAttribute() | ||||
|     { | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($this->id); | ||||
|         $cache->addProperty('destinationAccount'); | ||||
|  | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|         $account = $this->transactions()->where('amount', '>', 0)->first()->account; | ||||
|         $cache->store($account); | ||||
|  | ||||
|         return $account; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return Account | ||||
|      */ | ||||
|     public function getSourceAccountAttribute() | ||||
|     { | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($this->id); | ||||
|         $cache->addProperty('sourceAccount'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|         $account = $this->transactions()->where('amount', '<', 0)->first()->account; | ||||
|  | ||||
|         $cache->store($account); | ||||
|  | ||||
|         return $account; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
| @@ -253,7 +374,7 @@ class TransactionJournal extends Model | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Carbon          $date | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return EloquentBuilder | ||||
|      */ | ||||
|     public function scopeAfter(EloquentBuilder $query, Carbon $date) | ||||
|     { | ||||
| @@ -266,62 +387,26 @@ class TransactionJournal extends Model | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Carbon          $date | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return EloquentBuilder | ||||
|      */ | ||||
|     public function scopeBefore(EloquentBuilder $query, Carbon $date) | ||||
|     { | ||||
|         return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param                 $amount | ||||
|      */ | ||||
|     public function scopeLessThan(EloquentBuilder $query, $amount) | ||||
|     { | ||||
|         if (is_null($this->joinedTransactions)) { | ||||
|             $query->leftJoin( | ||||
|                 'transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id' | ||||
|             ); | ||||
|             $this->joinedTransactions = true; | ||||
|         } | ||||
|  | ||||
|         $query->where('transactions.amount', '<=', $amount); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Carbon          $date | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return EloquentBuilder | ||||
|      */ | ||||
|     public function scopeOnDate(EloquentBuilder $query, Carbon $date) | ||||
|     { | ||||
|         return $query->where('date', '=', $date->format('Y-m-d')); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the account to which the money was moved. | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param EloquentBuilder $query | ||||
|      * @param Account         $account | ||||
|      */ | ||||
|     public function scopeToAccountIs(EloquentBuilder $query, Account $account) | ||||
|     { | ||||
|         $query->leftJoin( | ||||
|             'transactions', function (JoinClause $join) { | ||||
|             $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0); | ||||
|         } | ||||
|         ); | ||||
|         $query->where('transactions.account_id', $account->id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
| @@ -351,7 +436,7 @@ class TransactionJournal extends Model | ||||
|         $query->with( | ||||
|             ['transactions' => function (HasMany $q) { | ||||
|                 $q->orderBy('amount', 'ASC'); | ||||
|             }, 'transactiontype', 'transactioncurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] | ||||
|             }, 'transactionType', 'transactionCurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill'] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Model; | ||||
| /** | ||||
|  * Class TransactionRelation | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  */ | ||||
| class TransactionRelation extends Model | ||||
|   | ||||
| @@ -6,8 +6,19 @@ use Illuminate\Database\Eloquent\SoftDeletes; | ||||
| /** | ||||
|  * Class TransactionType | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @codeCoverageIgnore  | ||||
|  * @package FireflyIII\Models | ||||
|  * @property integer                                                                               $id | ||||
|  * @property \Carbon\Carbon                                                                        $created_at | ||||
|  * @property \Carbon\Carbon                                                                        $updated_at | ||||
|  * @property \Carbon\Carbon                                                                        $deleted_at | ||||
|  * @property string                                                                                $type | ||||
|  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionJournals | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereId($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereCreatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereDeletedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionType whereType($value) | ||||
|  */ | ||||
| class TransactionType extends Model | ||||
| { | ||||
|   | ||||
| @@ -6,6 +6,8 @@ use Illuminate\Support\ServiceProvider; | ||||
|  * Class AppServiceProvider | ||||
|  * | ||||
|  * @package FireflyIII\Providers | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  */ | ||||
| class AppServiceProvider extends ServiceProvider | ||||
| { | ||||
|   | ||||
| @@ -6,6 +6,8 @@ use Illuminate\Support\ServiceProvider; | ||||
| /** | ||||
|  * Class BusServiceProvider | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * | ||||
|  * @package FireflyIII\Providers | ||||
|  */ | ||||
| class BusServiceProvider extends ServiceProvider | ||||
|   | ||||
| @@ -6,6 +6,8 @@ use Illuminate\Support\ServiceProvider; | ||||
|  * Class ConfigServiceProvider | ||||
|  * | ||||
|  * @package FireflyIII\Providers | ||||
|  * @codeCoverageIgnore | ||||
|  * | ||||
|  */ | ||||
| class ConfigServiceProvider extends ServiceProvider | ||||
| { | ||||
| @@ -23,232 +25,7 @@ class ConfigServiceProvider extends ServiceProvider | ||||
|      */ | ||||
|     public function register() | ||||
|     { | ||||
|         config( | ||||
|             [ | ||||
|                 'twigbridge' => [ | ||||
|  | ||||
|                     'twig'       => [ | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Extension | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | File extension for Twig view files. | ||||
|                         | | ||||
|                         */ | ||||
|                         'extension'   => 'twig', | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Accepts all Twig environment configuration options | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | http://twig.sensiolabs.org/doc/api.html#environment-options | ||||
|                         | | ||||
|                         */ | ||||
|                         'environment' => [ | ||||
|  | ||||
|                             // When set to true, the generated templates have a __toString() method | ||||
|                             // that you can use to display the generated nodes. | ||||
|                             // default: false | ||||
|                             'debug'               => config('app.debug', false), | ||||
|  | ||||
|                             // The charset used by the templates. | ||||
|                             // default: utf-8 | ||||
|                             'charset'             => 'utf-8', | ||||
|  | ||||
|                             // The base template class to use for generated templates. | ||||
|                             // default: TwigBridge\Twig\Template | ||||
|                             'base_template_class' => 'TwigBridge\Twig\Template', | ||||
|  | ||||
|                             // An absolute path where to store the compiled templates, or false to disable caching. If null | ||||
|                             // then the cache file path is used. | ||||
|                             // default: cache file storage path | ||||
|                             'cache'               => null, | ||||
|  | ||||
|                             // When developing with Twig, it's useful to recompile the template | ||||
|                             // whenever the source code changes. If you don't provide a value | ||||
|                             // for the auto_reload option, it will be determined automatically based on the debug value. | ||||
|                             'auto_reload'         => true, | ||||
|  | ||||
|                             // If set to false, Twig will silently ignore invalid variables | ||||
|                             // (variables and or attributes/methods that do not exist) and | ||||
|                             // replace them with a null value. When set to true, Twig throws an exception instead. | ||||
|                             // default: false | ||||
|                             'strict_variables'    => false, | ||||
|  | ||||
|                             // If set to true, auto-escaping will be enabled by default for all templates. | ||||
|                             // default: true | ||||
|                             'autoescape'          => true, | ||||
|  | ||||
|                             // A flag that indicates which optimizations to apply | ||||
|                             // (default to -1 -- all optimizations are enabled; set it to 0 to disable) | ||||
|                             'optimizations'       => -1, | ||||
|                         ], | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Global variables | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | These will always be passed in and can be accessed as Twig variables. | ||||
|                         | NOTE: these will be overwritten if you pass data into the view with the same key. | ||||
|                         | | ||||
|                         */ | ||||
|                         'globals'     => [], | ||||
|                     ], | ||||
|  | ||||
|                     'extensions' => [ | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Extensions | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | Enabled extensions. | ||||
|                         | | ||||
|                         | `Twig_Extension_Debug` is enabled automatically if twig.debug is TRUE. | ||||
|                         | | ||||
|                         */ | ||||
|                         'enabled'   => [ | ||||
|                             'TwigBridge\Extension\Loader\Facades', | ||||
|                             'TwigBridge\Extension\Loader\Filters', | ||||
|                             'TwigBridge\Extension\Loader\Functions', | ||||
|  | ||||
|                             'TwigBridge\Extension\Laravel\Auth', | ||||
|                             'TwigBridge\Extension\Laravel\Config', | ||||
|                             'TwigBridge\Extension\Laravel\Dump', | ||||
|                             'TwigBridge\Extension\Laravel\Input', | ||||
|                             'TwigBridge\Extension\Laravel\Session', | ||||
|                             'TwigBridge\Extension\Laravel\String', | ||||
|                             'TwigBridge\Extension\Laravel\Translator', | ||||
|                             'TwigBridge\Extension\Laravel\Url', | ||||
|  | ||||
|                             //                             'TwigBridge\Extension\Laravel\Form', | ||||
|                             // 'TwigBridge\Extension\Laravel\Html', | ||||
|                             // 'TwigBridge\Extension\Laravel\Legacy\Facades', | ||||
|                         ], | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Facades | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | Available facades. Access like `{{ Config.get('foo.bar') }}`. | ||||
|                         | | ||||
|                         | Each facade can take an optional array of options. To mark the whole facade | ||||
|                         | as safe you can set the option `'is_safe' => true`. Setting the facade as | ||||
|                         | safe means that any HTML returned will not be escaped. | ||||
|                         | | ||||
|                         | It is advisable to not set the whole facade as safe and instead mark the | ||||
|                         | each appropriate method as safe for security reasons. You can do that with | ||||
|                         | the following syntax: | ||||
|                         | | ||||
|                         | <code> | ||||
|                         |     'Form' => [ | ||||
|                         |         'is_safe' => [ | ||||
|                         |             'open' | ||||
|                         |         ] | ||||
|                         |     ] | ||||
|                         | </code> | ||||
|                         | | ||||
|                         | The values of the `is_safe` array must match the called method on the facade | ||||
|                         | in order to be marked as safe. | ||||
|                         | | ||||
|                         */ | ||||
|                         'facades'   => [ | ||||
|                             'Breadcrumbs'  => [ | ||||
|                                 'is_safe' => [ | ||||
|                                     'renderIfExists' | ||||
|                                 ] | ||||
|                             ], | ||||
|                             'Session', | ||||
|                             'Route', | ||||
|                             'Auth', | ||||
|                             'Lang', | ||||
|                             'URL', | ||||
|                             'Config', | ||||
|                             'ExpandedForm' => [ | ||||
|                                 'is_safe' => [ | ||||
|                                     'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', | ||||
|                                     'multiRadio' | ||||
|                                 ] | ||||
|                             ], | ||||
|                             'Form'         => [ | ||||
|                                 'is_safe' => [ | ||||
|                                     'input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea' | ||||
|                                 ] | ||||
|                             ], | ||||
|                         ], | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Functions | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | Available functions. Access like `{{ secure_url(...) }}`. | ||||
|                         | | ||||
|                         | Each function can take an optional array of options. These options are | ||||
|                         | passed directly to `Twig_SimpleFunction`. | ||||
|                         | | ||||
|                         | So for example, to mark a function as safe you can do the following: | ||||
|                         | | ||||
|                         | <code> | ||||
|                         |     'link_to' => [ | ||||
|                         |         'is_safe' => ['html'] | ||||
|                         |     ] | ||||
|                         | </code> | ||||
|                         | | ||||
|                         | The options array also takes a `callback` that allows you to name the | ||||
|                         | function differently in your Twig templates than what it's actually called. | ||||
|                         | | ||||
|                         | <code> | ||||
|                         |     'link' => [ | ||||
|                         |         'callback' => 'link_to' | ||||
|                         |     ] | ||||
|                         | </code> | ||||
|                         | | ||||
|                         */ | ||||
|                         'functions' => [ | ||||
|                             'elixir', | ||||
|                             'head', | ||||
|                             'last', | ||||
|                             'old' | ||||
|                         ], | ||||
|  | ||||
|                         /* | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | Filters | ||||
|                         |-------------------------------------------------------------------------- | ||||
|                         | | ||||
|                         | Available filters. Access like `{{ variable|filter }}`. | ||||
|                         | | ||||
|                         | Each filter can take an optional array of options. These options are | ||||
|                         | passed directly to `Twig_SimpleFilter`. | ||||
|                         | | ||||
|                         | So for example, to mark a filter as safe you can do the following: | ||||
|                         | | ||||
|                         | <code> | ||||
|                         |     'studly_case' => [ | ||||
|                         |         'is_safe' => ['html'] | ||||
|                         |     ] | ||||
|                         | </code> | ||||
|                         | | ||||
|                         | The options array also takes a `callback` that allows you to name the | ||||
|                         | filter differently in your Twig templates than what is actually called. | ||||
|                         | | ||||
|                         | <code> | ||||
|                         |     'snake' => [ | ||||
|                         |         'callback' => 'snake_case' | ||||
|                         |     ] | ||||
|                         | </code> | ||||
|                         | | ||||
|                         */ | ||||
|                         'filters'   => [], | ||||
|                     ], | ||||
|                 ] | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -53,10 +53,13 @@ class EventServiceProvider extends ServiceProvider | ||||
|         $this->registerCreateEvents(); | ||||
|         BudgetLimit::saved( | ||||
|             function (BudgetLimit $budgetLimit) { | ||||
|                 Log::debug('Saved!'); | ||||
|  | ||||
|                 $end = Navigation::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); | ||||
|                 $end->subDay(); | ||||
|                 $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d')) | ||||
|                 $set = $budgetLimit->limitrepetitions() | ||||
|                                    ->where('startdate', $budgetLimit->startdate->format('Y-m-d 00:00:00')) | ||||
|                                    ->where('enddate', $end->format('Y-m-d 00:00:00')) | ||||
|                                    ->get(); | ||||
|                 if ($set->count() == 0) { | ||||
|                     $repetition            = new LimitRepetition; | ||||
| @@ -68,8 +71,7 @@ class EventServiceProvider extends ServiceProvider | ||||
|                     try { | ||||
|                         $repetition->save(); | ||||
|                     } catch (QueryException $e) { | ||||
|                         Log::error('Trying to save new LimitRepetition failed!'); | ||||
|                         Log::error($e->getMessage()); | ||||
|                         Log::error('Trying to save new LimitRepetition failed: ' . $e->getMessage()); // @codeCoverageIgnore | ||||
|                     } | ||||
|                 } else { | ||||
|                     if ($set->count() == 1) { | ||||
|   | ||||
| @@ -23,6 +23,7 @@ use Validator; | ||||
|  * Class FireflyServiceProvider | ||||
|  * | ||||
|  * @package FireflyIII\Providers | ||||
|  * @codeCoverageIgnore | ||||
|  */ | ||||
| class FireflyServiceProvider extends ServiceProvider | ||||
| { | ||||
|   | ||||
| @@ -7,6 +7,7 @@ use Illuminate\Routing\Router; | ||||
|  * Class RouteServiceProvider | ||||
|  * | ||||
|  * @package FireflyIII\Providers | ||||
|  * @codeCoverageIgnore | ||||
|  */ | ||||
| class RouteServiceProvider extends ServiceProvider | ||||
| { | ||||
|   | ||||
| @@ -8,6 +8,7 @@ use Illuminate\Support\ServiceProvider; | ||||
| /** | ||||
|  * Class TestingServiceProvider | ||||
|  * | ||||
|  * @codeCoverageIgnore | ||||
|  * @package FireflyIII\Providers | ||||
|  */ | ||||
| class TestingServiceProvider extends ServiceProvider | ||||
|   | ||||
| @@ -15,6 +15,7 @@ use FireflyIII\Models\Preference; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Models\TransactionType; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Database\Eloquent\Relations\HasMany; | ||||
| use Illuminate\Database\Query\Builder; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| @@ -25,6 +26,8 @@ use Steam; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @SuppressWarnings(PHPMD.TooManyMethods) | ||||
|  * | ||||
|  * Class AccountRepository | ||||
|  * | ||||
|  * @package FireflyIII\Repositories\Account | ||||
| @@ -65,7 +68,7 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|             ['accountmeta' => function (HasMany $query) { | ||||
|                 $query->where('name', 'accountRole'); | ||||
|             }] | ||||
|         )->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*'])->sortBy('name'); | ||||
|         )->accountTypeIn($types)->orderBy('accounts.name', 'ASC')->get(['accounts.*']); | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
| @@ -107,12 +110,22 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|      */ | ||||
|     public function getFrontpageAccounts(Preference $preference) | ||||
|     { | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($preference->data); | ||||
|         $cache->addProperty('frontPageaccounts'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|  | ||||
|         if ($preference->data == []) { | ||||
|             $accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']); | ||||
|         } else { | ||||
|             $accounts = Auth::user()->accounts()->whereIn('id', $preference->data)->orderBy('accounts.name', 'ASC')->get(['accounts.*']); | ||||
|         } | ||||
|  | ||||
|         $cache->store($accounts); | ||||
|  | ||||
|         return $accounts; | ||||
|     } | ||||
|  | ||||
| @@ -129,7 +142,15 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|      */ | ||||
|     public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end) | ||||
|     { | ||||
|         return Auth::user() | ||||
|         $cache = new CacheProperties(); | ||||
|         $cache->addProperty($account->id); | ||||
|         $cache->addProperty($start); | ||||
|         $cache->addProperty($end); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $set = Auth::user() | ||||
|                    ->transactionjournals() | ||||
|                    ->with(['transactions']) | ||||
|                    ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') | ||||
| @@ -142,6 +163,9 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|                    ->orderBy('transaction_journals.id', 'DESC') | ||||
|                    ->take(10) | ||||
|                    ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']); | ||||
|         $cache->store($set); | ||||
|  | ||||
|         return $set; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -205,6 +229,13 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|             $ids[] = intval($id->account_id); | ||||
|         } | ||||
|  | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($ids); | ||||
|         $cache->addProperty('piggyAccounts'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $ids = array_unique($ids); | ||||
|         if (count($ids) > 0) { | ||||
|             $accounts = Auth::user()->accounts()->whereIn('id', $ids)->get(); | ||||
| @@ -229,6 +260,8 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         $cache->store($accounts); | ||||
|  | ||||
|         return $accounts; | ||||
|  | ||||
|     } | ||||
| @@ -287,7 +320,7 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|      */ | ||||
|     public function getTransfersInRange(Account $account, Carbon $start, Carbon $end) | ||||
|     { | ||||
|         return TransactionJournal::whereIn( | ||||
|         $set      = TransactionJournal::whereIn( | ||||
|             'id', function (Builder $q) use ($account, $start, $end) { | ||||
|             $q->select('transaction_journals.id') | ||||
|               ->from('transactions') | ||||
| @@ -297,11 +330,21 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|               ->where('transaction_journals.user_id', Auth::user()->id) | ||||
|               ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) | ||||
|               ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) | ||||
|               ->where('transactions.amount', '>', 0) | ||||
|               ->where('transaction_types.type', 'Transfer'); | ||||
|  | ||||
|         } | ||||
|         )->get(); | ||||
|         $filtered = $set->filter( | ||||
|             function (TransactionJournal $journal) use ($account) { | ||||
|                 if ($journal->destination_account->id == $account->id) { | ||||
|                     return $journal; | ||||
|                 } | ||||
|  | ||||
|                 return null; | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         return $filtered; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -330,16 +373,17 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|      */ | ||||
|     public function openingBalanceTransaction(Account $account) | ||||
|     { | ||||
|         return TransactionJournal::accountIs($account) | ||||
|                                  ->orderBy('transaction_journals.date', 'ASC') | ||||
|                                  ->orderBy('created_at', 'ASC') | ||||
|                                  ->first(['transaction_journals.*']); | ||||
|         return TransactionJournal | ||||
|             ::orderBy('transaction_journals.date', 'ASC') | ||||
|             ->accountIs($account) | ||||
|             ->orderBy('created_at', 'ASC') | ||||
|             ->first(['transaction_journals.*']); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $data | ||||
|      * | ||||
|      * @return Account; | ||||
|      * @return Account | ||||
|      */ | ||||
|     public function store(array $data) | ||||
|     { | ||||
| @@ -351,11 +395,11 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|         if ($data['openingBalance'] != 0) { | ||||
|             $type         = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; | ||||
|             $opposingData = [ | ||||
|                 'user'            => $data['user'], | ||||
|                 'accountType'     => $type, | ||||
|                 'virtual_balance' => $data['virtualBalance'], | ||||
|                 'name'            => $data['name'] . ' initial balance', | ||||
|                 'active'          => false, | ||||
|                 'user'           => $data['user'], | ||||
|                 'accountType'    => $type, | ||||
|                 'virtualBalance' => 0, | ||||
|                 'name'           => $data['name'] . ' initial balance', | ||||
|                 'active'         => false, | ||||
|             ]; | ||||
|             $opposing     = $this->storeAccount($opposingData); | ||||
|             $this->storeInitialBalance($newAccount, $opposing, $data); | ||||
| @@ -390,7 +434,6 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|  | ||||
|         // update meta data: | ||||
|         $this->updateMetadata($account, $data); | ||||
|  | ||||
|         $openingBalance = $this->openingBalanceTransaction($account); | ||||
|  | ||||
|         // if has openingbalance? | ||||
| @@ -403,20 +446,19 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|                 // create new opening balance. | ||||
|                 $type         = $data['openingBalance'] < 0 ? 'expense' : 'revenue'; | ||||
|                 $opposingData = [ | ||||
|                     'user'        => $data['user'], | ||||
|                     'accountType' => $type, | ||||
|                     'name'        => $data['name'] . ' initial balance', | ||||
|                     'active'      => false, | ||||
|                     'user'           => $data['user'], | ||||
|                     'accountType'    => $type, | ||||
|                     'name'           => $data['name'] . ' initial balance', | ||||
|                     'active'         => false, | ||||
|                     'virtualBalance' => 0, | ||||
|                 ]; | ||||
|                 $opposing     = $this->storeAccount($opposingData); | ||||
|                 $this->storeInitialBalance($account, $opposing, $data); | ||||
|             } | ||||
|  | ||||
|         } else { | ||||
|             // opening balance is zero, should we delete it? | ||||
|             if ($openingBalance) { | ||||
|                 // delete existing opening balance. | ||||
|                 $openingBalance->delete(); | ||||
|             if ($openingBalance) { // opening balance is zero, should we delete it? | ||||
|                 $openingBalance->delete(); // delete existing opening balance. | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -437,6 +479,7 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|                 'user_id'         => $data['user'], | ||||
|                 'account_type_id' => $accountType->id, | ||||
|                 'name'            => $data['name'], | ||||
|                 'virtual_balance' => $data['virtualBalance'], | ||||
|                 'active'          => $data['active'] === true ? true : false, | ||||
|             ] | ||||
|         ); | ||||
| @@ -446,6 +489,7 @@ class AccountRepository implements AccountRepositoryInterface | ||||
|             $searchData      = [ | ||||
|                 'user_id'         => $data['user'], | ||||
|                 'account_type_id' => $accountType->id, | ||||
|                 'virtual_balance' => $data['virtualBalance'], | ||||
|                 'name'            => $data['name'] | ||||
|             ]; | ||||
|             $existingAccount = Account::firstOrNullEncrypted($searchData); | ||||
|   | ||||
| @@ -5,14 +5,10 @@ namespace FireflyIII\Repositories\Bill; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use DB; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\Bill; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use Illuminate\Database\Query\JoinClause; | ||||
| use Illuminate\Support\Collection; | ||||
| use Log; | ||||
| use Navigation; | ||||
|  | ||||
| /** | ||||
| @@ -29,7 +25,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * | ||||
|      * @return float | ||||
|      * @return integer | ||||
|      */ | ||||
|     public function billPaymentsInRange(Bill $bill, Carbon $start, Carbon $end) | ||||
|     { | ||||
| @@ -71,7 +67,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|     /** | ||||
|      * @param Bill $bill | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return boolean|null | ||||
|      */ | ||||
|     public function destroy(Bill $bill) | ||||
|     { | ||||
| @@ -95,7 +91,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|     public function getBills() | ||||
|     { | ||||
|         /** @var Collection $set */ | ||||
|         $set = Auth::user()->bills()->orderBy('name', 'ASC')->get()->sortBy('name'); | ||||
|         $set = Auth::user()->bills()->orderBy('name', 'ASC')->get(); | ||||
|  | ||||
|         return $set; | ||||
|     } | ||||
| @@ -108,16 +104,10 @@ class BillRepository implements BillRepositoryInterface | ||||
|     public function getJournals(Bill $bill) | ||||
|     { | ||||
|         return $bill->transactionjournals()->withRelevantData() | ||||
|                     ->leftJoin( | ||||
|                         'transactions', function (JoinClause $join) { | ||||
|                         $join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id') | ||||
|                              ->where('transactions.amount', '>', 0); | ||||
|                     } | ||||
|                     ) | ||||
|                     ->orderBy('transaction_journals.date', 'DESC') | ||||
|                     ->orderBy('transaction_journals.order', 'ASC') | ||||
|                     ->orderBy('transaction_journals.id', 'DESC') | ||||
|                     ->get(['transaction_journals.*', 'transactions.amount']); | ||||
|                     ->get(['transaction_journals.*']); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -219,7 +209,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|     /** | ||||
|      * @param Bill $bill | ||||
|      * | ||||
|      * @return Carbon | ||||
|      * @return \Carbon\Carbon | ||||
|      */ | ||||
|     public function nextExpectedMatch(Bill $bill) | ||||
|     { | ||||
| @@ -251,7 +241,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|                 $end          = Navigation::endOfPeriod(clone $start, $bill->repeat_freq); | ||||
|                 $journalCount = $bill->transactionjournals()->before($end)->after($start)->count(); | ||||
|                 if ($journalCount == 0) { | ||||
|                     $finalDate = clone $start; | ||||
|                     $finalDate = new Carbon($start->format('Y-m-d')); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| @@ -268,77 +258,34 @@ class BillRepository implements BillRepositoryInterface | ||||
|      * @param Bill               $bill | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return bool | ||||
|      * @return boolean|null | ||||
|      */ | ||||
|     public function scan(Bill $bill, TransactionJournal $journal) | ||||
|     { | ||||
|         $amountMatch = false; | ||||
|         $wordMatch   = false; | ||||
|         $matches     = explode(',', $bill->match); | ||||
|         $description = strtolower($journal->description); | ||||
|  | ||||
|         /* | ||||
|          * Attach expense account to description for more narrow matching. | ||||
|          */ | ||||
|         $transactions = $journal->transactions()->get(); | ||||
|  | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($transactions as $transaction) { | ||||
|             /** @var Account $account */ | ||||
|             $account = $transaction->account()->first(); | ||||
|             /** @var AccountType $type */ | ||||
|             $type = $account->accountType()->first(); | ||||
|             if ($type->type == 'Expense account' || $type->type == 'Beneficiary account') { | ||||
|                 $description .= ' ' . strtolower($account->name); | ||||
|             } | ||||
|         } | ||||
|         Log::debug('Final description: ' . $description); | ||||
|         Log::debug('Matches searched: ' . join(':', $matches)); | ||||
|  | ||||
|         $count = 0; | ||||
|         foreach ($matches as $word) { | ||||
|             if (!(strpos($description, strtolower($word)) === false)) { | ||||
|                 $count++; | ||||
|             } | ||||
|         } | ||||
|         if ($count >= count($matches)) { | ||||
|             $wordMatch = true; | ||||
|             Log::debug('word match is true'); | ||||
|         } else { | ||||
|             Log::debug('Count: ' . $count . ', count(matches): ' . count($matches)); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /* | ||||
|          * Match amount. | ||||
|          */ | ||||
|  | ||||
|         if (count($transactions) > 1) { | ||||
|  | ||||
|             $amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount)); | ||||
|             $min    = floatval($bill->amount_min); | ||||
|             $max    = floatval($bill->amount_max); | ||||
|             if ($amount >= $min && $amount <= $max) { | ||||
|                 $amountMatch = true; | ||||
|                 Log::debug('Amount match is true!'); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $description = strtolower($journal->description) . ' ' . strtolower($journal->destination_account->name); | ||||
|         $wordMatch   = $this->doWordMatch($matches, $description); | ||||
|         $amountMatch = $this->doAmountMatch($journal->amount, $bill->amount_min, $bill->amount_max); | ||||
|  | ||||
|         /* | ||||
|          * If both, update! | ||||
|          */ | ||||
|         if ($wordMatch && $amountMatch) { | ||||
|             Log::debug('TOTAL match is true!'); | ||||
|             $journal->bill()->associate($bill); | ||||
|             $journal->save(); | ||||
|         } else { | ||||
|             if ((!$wordMatch || !$amountMatch) && $bill->id == $journal->bill_id) { | ||||
|                 // if no match, but bill used to match, remove it: | ||||
|                 $journal->bill_id = null; | ||||
|                 $journal->save(); | ||||
|             } | ||||
|  | ||||
|             return true; | ||||
|         } | ||||
|         if ($bill->id == $journal->bill_id) { | ||||
|             // if no match, but bill used to match, remove it: | ||||
|             $journal->bill_id = null; | ||||
|             $journal->save(); | ||||
|  | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -373,7 +320,7 @@ class BillRepository implements BillRepositoryInterface | ||||
|      * @param Bill  $bill | ||||
|      * @param array $data | ||||
|      * | ||||
|      * @return Bill|static | ||||
|      * @return Bill | ||||
|      */ | ||||
|     public function update(Bill $bill, array $data) | ||||
|     { | ||||
| @@ -392,4 +339,42 @@ class BillRepository implements BillRepositoryInterface | ||||
|  | ||||
|         return $bill; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $matches | ||||
|      * @param       $description | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     protected function doWordMatch(array $matches, $description) | ||||
|     { | ||||
|         $wordMatch = false; | ||||
|         $count     = 0; | ||||
|         foreach ($matches as $word) { | ||||
|             if (!(strpos($description, strtolower($word)) === false)) { | ||||
|                 $count++; | ||||
|             } | ||||
|         } | ||||
|         if ($count >= count($matches)) { | ||||
|             $wordMatch = true; | ||||
|         } | ||||
|  | ||||
|         return $wordMatch; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param float $amount | ||||
|      * @param float $min | ||||
|      * @param float $max | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     protected function doAmountMatch($amount, $min, $max) | ||||
|     { | ||||
|         if ($amount >= $min && $amount <= $max) { | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -103,7 +103,7 @@ interface BillRepositoryInterface | ||||
|     /** | ||||
|      * @param Bill $bill | ||||
|      * | ||||
|      * @return Carbon|null | ||||
|      * @return \Carbon\Carbon | ||||
|      */ | ||||
|     public function nextExpectedMatch(Bill $bill); | ||||
|  | ||||
|   | ||||
| @@ -7,8 +7,9 @@ use Carbon\Carbon; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\BudgetLimit; | ||||
| use FireflyIII\Models\LimitRepetition; | ||||
| use FireflyIII\Repositories\Shared\ComponentRepository; | ||||
| use FireflyIII\Support\CacheProperties; | ||||
| use Illuminate\Database\Query\Builder as QueryBuilder; | ||||
| use Illuminate\Database\Query\JoinClause; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
| use Input; | ||||
| @@ -18,7 +19,7 @@ use Input; | ||||
|  * | ||||
|  * @package FireflyIII\Repositories\Budget | ||||
|  */ | ||||
| class BudgetRepository implements BudgetRepositoryInterface | ||||
| class BudgetRepository extends ComponentRepository implements BudgetRepositoryInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
| @@ -62,7 +63,6 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|     public function getActiveBudgets() | ||||
|     { | ||||
|         $budgets = Auth::user()->budgets()->where('active', 1)->get(); | ||||
|         $budgets->sortBy('name'); | ||||
|  | ||||
|         return $budgets; | ||||
|     } | ||||
| @@ -113,7 +113,17 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|      */ | ||||
|     public function getCurrentRepetition(Budget $budget, Carbon $date) | ||||
|     { | ||||
|         return $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']); | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($budget->id); | ||||
|         $cache->addProperty($date); | ||||
|         $cache->addProperty('getCurrentRepetition'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|         $data = $budget->limitrepetitions()->where('limit_repetitions.startdate', $date)->first(['limit_repetitions.*']); | ||||
|         $cache->store($data); | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -146,13 +156,22 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|      * @param LimitRepetition $repetition | ||||
|      * @param int             $take | ||||
|      * | ||||
|      * @return \Illuminate\Pagination\Paginator | ||||
|      * @return LengthAwarePaginator | ||||
|      */ | ||||
|     public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50) | ||||
|     { | ||||
|         $offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0; | ||||
|  | ||||
|         $cache = new CacheProperties; | ||||
|         $cache->addProperty($budget->id); | ||||
|         if ($repetition) { | ||||
|             $cache->addProperty($repetition->id); | ||||
|         } | ||||
|         $cache->addProperty($take); | ||||
|         $cache->addProperty('getJournals'); | ||||
|         if ($cache->has()) { | ||||
|             return $cache->get(); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         $offset     = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0; | ||||
|         $setQuery   = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) | ||||
|                              ->orderBy('transaction_journals.date', 'DESC') | ||||
|                              ->orderBy('transaction_journals.order', 'ASC') | ||||
| @@ -169,7 +188,11 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|         $set   = $setQuery->get(['transaction_journals.*']); | ||||
|         $count = $countQuery->count(); | ||||
|  | ||||
|         return new LengthAwarePaginator($set, $count, $take, $offset); | ||||
|  | ||||
|         $paginator = new LengthAwarePaginator($set, $count, $take, $offset); | ||||
|         $cache->store($paginator); | ||||
|  | ||||
|         return $paginator; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -231,7 +254,7 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return double | ||||
|      */ | ||||
|     public function getWithoutBudgetSum(Carbon $start, Carbon $end) | ||||
|     { | ||||
| @@ -250,9 +273,8 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|                            ) | ||||
|                            ->after($start) | ||||
|                            ->before($end) | ||||
|                            ->lessThan(0) | ||||
|                            ->transactionTypes(['Withdrawal']) | ||||
|                            ->sum('transactions.amount'); | ||||
|                            ->get(['transaction_journals.*'])->sum('amount'); | ||||
|  | ||||
|         return floatval($noBudgetSet) * -1; | ||||
|     } | ||||
| @@ -263,32 +285,11 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|      * @param Carbon $end | ||||
|      * @param bool   $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true) | ||||
|     { | ||||
|         if ($shared === true) { | ||||
|             // get everything: | ||||
|             $sum = floatval($budget->transactionjournals()->before($end)->after($start)->lessThan(0)->get(['transaction_journals.*'])->sum('amount')); | ||||
|         } else { | ||||
|             // get all journals in this month where the asset account is NOT shared. | ||||
|             $sum = $budget->transactionjournals() | ||||
|                           ->before($end) | ||||
|                           ->after($start) | ||||
|                           ->lessThan(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"') | ||||
|                           ->get(['transaction_journals.*']) | ||||
|                           ->sum('amount'); | ||||
|             $sum = floatval($sum); | ||||
|         } | ||||
|  | ||||
|         return $sum; | ||||
|         return $this->spentInPeriod($budget, $start, $end, $shared); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -310,7 +311,6 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @param Budget $budget | ||||
|      * @param array  $data | ||||
| @@ -332,7 +332,7 @@ class BudgetRepository implements BudgetRepositoryInterface | ||||
|      * @param Carbon $date | ||||
|      * @param        $amount | ||||
|      * | ||||
|      * @return LimitRepetition|null | ||||
|      * @return BudgetLimit | ||||
|      */ | ||||
|     public function updateLimitAmount(Budget $budget, Carbon $date, $amount) | ||||
|     { | ||||
|   | ||||
| @@ -5,6 +5,7 @@ namespace FireflyIII\Repositories\Budget; | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\LimitRepetition; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
| @@ -89,7 +90,7 @@ interface BudgetRepositoryInterface | ||||
|      * @param LimitRepetition $repetition | ||||
|      * @param int             $take | ||||
|      * | ||||
|      * @return \Illuminate\Pagination\Paginator | ||||
|      * @return LengthAwarePaginator | ||||
|      */ | ||||
|     public function getJournals(Budget $budget, LimitRepetition $repetition = null, $take = 50); | ||||
|  | ||||
| @@ -133,7 +134,7 @@ interface BudgetRepositoryInterface | ||||
|      * @param Carbon  $end | ||||
|      * @param boolean $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentInPeriodCorrected(Budget $budget, Carbon $start, Carbon $end, $shared = true); | ||||
|  | ||||
|   | ||||
| @@ -5,10 +5,9 @@ namespace FireflyIII\Repositories\Category; | ||||
| use Auth; | ||||
| use Carbon\Carbon; | ||||
| use Crypt; | ||||
| use DB; | ||||
| use FireflyIII\Models\Category; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use Illuminate\Database\Query\JoinClause; | ||||
| use FireflyIII\Repositories\Shared\ComponentRepository; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
| @@ -16,7 +15,7 @@ use Illuminate\Support\Collection; | ||||
|  * | ||||
|  * @package FireflyIII\Repositories\Category | ||||
|  */ | ||||
| class CategoryRepository implements CategoryRepositoryInterface | ||||
| class CategoryRepository extends ComponentRepository implements CategoryRepositoryInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
| @@ -49,7 +48,7 @@ class CategoryRepository implements CategoryRepositoryInterface | ||||
|     { | ||||
|         /** @var Collection $set */ | ||||
|         $set = Auth::user()->categories()->orderBy('name', 'ASC')->get(); | ||||
|         $set->sortBy( | ||||
|         $set = $set->sortBy( | ||||
|             function (Category $category) { | ||||
|                 return $category->name; | ||||
|             } | ||||
| @@ -63,7 +62,7 @@ class CategoryRepository implements CategoryRepositoryInterface | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * | ||||
|      * @return Collection | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getCategoriesAndExpensesCorrected($start, $end) | ||||
|     { | ||||
| @@ -76,17 +75,17 @@ class CategoryRepository implements CategoryRepositoryInterface | ||||
|                    ->where('categories.user_id', Auth::user()->id) | ||||
|                    ->after($start) | ||||
|                    ->transactionTypes(['Withdrawal']) | ||||
|                    ->groupBy('categories.id') | ||||
|                    ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); | ||||
|  | ||||
|         $result = []; | ||||
|         foreach ($set as $entry) { | ||||
|             $categoryId = intval($entry->category_id); | ||||
|             if (isset($result[$categoryId])) { | ||||
|                 $result[$categoryId]['sum'] += floatval($entry->amount); | ||||
|                 bcscale(2); | ||||
|                 $result[$categoryId]['sum'] = bcadd($result[$categoryId]['sum'], $entry->amount); | ||||
|             } else { | ||||
|                 $isEncrypted         = intval($entry->category_encrypted) == 1 ? true : false; | ||||
|                 $name                = strlen($entry->name) == 0 ? trans('firefly.noCategory') : $entry->name; | ||||
|                 $name                = strlen($entry->name) == 0 ? trans('firefly.no_category') : $entry->name; | ||||
|                 $name                = $isEncrypted ? Crypt::decrypt($name) : $name; | ||||
|                 $result[$categoryId] = [ | ||||
|                     'name' => $name, | ||||
| @@ -182,39 +181,11 @@ class CategoryRepository implements CategoryRepositoryInterface | ||||
|      * | ||||
|      * @param bool     $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false) | ||||
|     { | ||||
|         if ($shared === true) { | ||||
|             // shared is true. | ||||
|             // always ignore transfers between accounts! | ||||
|             $sum = floatval( | ||||
|                 $category->transactionjournals() | ||||
|                          ->transactionTypes(['Withdrawal']) | ||||
|                          ->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount') | ||||
|             ); | ||||
|  | ||||
|         } else { | ||||
|             // do something else, SEE budgets. | ||||
|             // get all journals in this month where the asset account is NOT shared. | ||||
|             $sum = $category->transactionjournals() | ||||
|                             ->before($end) | ||||
|                             ->after($start) | ||||
|                             ->transactionTypes(['Withdrawal']) | ||||
|                             ->lessThan(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"') | ||||
|                             ->get(['transaction_journals.*'])->sum('amount'); | ||||
|             $sum = floatval($sum); | ||||
|         } | ||||
|  | ||||
|         return $sum; | ||||
|         return $this->spentInPeriod($category, $start, $end, $shared); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -38,7 +38,7 @@ interface CategoryRepositoryInterface | ||||
|      * @param Carbon $start | ||||
|      * @param Carbon $end | ||||
|      * | ||||
|      * @return Collection | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getCategoriesAndExpensesCorrected($start, $end); | ||||
|  | ||||
| @@ -81,7 +81,7 @@ interface CategoryRepositoryInterface | ||||
|      * | ||||
|      * @param bool           $shared | ||||
|      * | ||||
|      * @return float | ||||
|      * @return string | ||||
|      */ | ||||
|     public function spentInPeriodCorrected(Category $category, Carbon $start, Carbon $end, $shared = false); | ||||
|  | ||||
|   | ||||
| @@ -29,7 +29,7 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|     /** | ||||
|      * @param int $reminderId | ||||
|      * | ||||
|      * @return bool | ||||
|      * @return boolean|null | ||||
|      */ | ||||
|     public function deactivateReminder($reminderId) | ||||
|     { | ||||
| @@ -48,11 +48,6 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|      */ | ||||
|     public function delete(TransactionJournal $journal) | ||||
|     { | ||||
|         // delete transactions first: | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($journal->transactions()->get() as $transaction) { | ||||
|             $transaction->delete(); | ||||
|         } | ||||
|         $journal->delete(); | ||||
|  | ||||
|         return true; | ||||
| @@ -72,19 +67,24 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param Transaction        $transaction | ||||
|      * | ||||
|      * @return float | ||||
|      * @return integer | ||||
|      */ | ||||
|     public function getAmountBefore(TransactionJournal $journal, Transaction $transaction) | ||||
|     { | ||||
|         return floatval( | ||||
|             $transaction->account->transactions()->leftJoin( | ||||
|                 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' | ||||
|             ) | ||||
|                                  ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) | ||||
|                                  ->where('transaction_journals.order', '>=', $journal->order) | ||||
|                                  ->where('transaction_journals.id', '!=', $journal->id) | ||||
|                                  ->sum('transactions.amount') | ||||
|         ); | ||||
|         $set = $transaction->account->transactions()->leftJoin( | ||||
|             'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' | ||||
|         ) | ||||
|                                     ->where('transaction_journals.date', '<=', $journal->date->format('Y-m-d')) | ||||
|                                     ->where('transaction_journals.order', '>=', $journal->order) | ||||
|                                     ->where('transaction_journals.id', '!=', $journal->id) | ||||
|                                     ->get(['transactions.*']); | ||||
|         $sum = 0; | ||||
|         foreach ($set as $entry) { | ||||
|             $sum += $entry->amount; | ||||
|         } | ||||
|  | ||||
|         return $sum; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -235,7 +235,7 @@ class JournalRepository implements JournalRepositoryInterface | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param array              $data | ||||
|      * | ||||
|      * @return mixed | ||||
|      * @return TransactionJournal | ||||
|      */ | ||||
|     public function update(TransactionJournal $journal, array $data) | ||||
|     { | ||||
|   | ||||
| @@ -7,7 +7,6 @@ use Carbon\Carbon; | ||||
| use DB; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\PiggyBankEvent; | ||||
| use FireflyIII\Models\PiggyBankRepetition; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
| @@ -34,7 +33,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return bool | ||||
|      * @return boolean|null | ||||
|      */ | ||||
|     public function destroy(PiggyBank $piggyBank) | ||||
|     { | ||||
|   | ||||
| @@ -3,7 +3,6 @@ | ||||
| namespace FireflyIII\Repositories\PiggyBank; | ||||
|  | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\PiggyBankRepetition; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
| @@ -14,18 +13,6 @@ use Illuminate\Support\Collection; | ||||
| interface PiggyBankRepositoryInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getPiggyBanks(); | ||||
|  | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getEvents(PiggyBank $piggyBank); | ||||
|  | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * @param           $amount | ||||
| @@ -34,6 +21,13 @@ interface PiggyBankRepositoryInterface | ||||
|      */ | ||||
|     public function createEvent(PiggyBank $piggyBank, $amount); | ||||
|  | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function destroy(PiggyBank $piggyBank); | ||||
|  | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
| @@ -44,9 +38,14 @@ interface PiggyBankRepositoryInterface | ||||
|     /** | ||||
|      * @param PiggyBank $piggyBank | ||||
|      * | ||||
|      * @return bool | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function destroy(PiggyBank $piggyBank); | ||||
|     public function getEvents(PiggyBank $piggyBank); | ||||
|  | ||||
|     /** | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getPiggyBanks(); | ||||
|  | ||||
|     /** | ||||
|      * Set all piggy banks to order 0. | ||||
|   | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user