| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * ExpandedForm.php | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2017-12-17 14:44:05 +01:00
										 |  |  |  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Support; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-21 21:33:52 +01:00
										 |  |  | use Amount as Amt; | 
					
						
							| 
									
										
										
										
											2016-04-29 17:29:13 +02:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2015-05-26 08:17:58 +02:00
										 |  |  | use Eloquent; | 
					
						
							| 
									
										
										
										
											2018-07-28 10:45:16 +02:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2018-03-07 10:18:22 +01:00
										 |  |  | use FireflyIII\Models\Account; | 
					
						
							|  |  |  | use FireflyIII\Models\AccountType; | 
					
						
							| 
									
										
										
										
											2018-06-17 15:14:34 +02:00
										 |  |  | use FireflyIII\Models\PiggyBank; | 
					
						
							| 
									
										
										
										
											2018-04-29 07:46:14 +02:00
										 |  |  | use FireflyIII\Models\RuleGroup; | 
					
						
							| 
									
										
										
										
											2018-04-28 05:40:08 +02:00
										 |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							| 
									
										
										
										
											2018-03-07 10:18:22 +01:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2018-06-17 15:14:34 +02:00
										 |  |  | use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2018-04-29 07:46:14 +02:00
										 |  |  | use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2019-08-10 15:09:44 +02:00
										 |  |  | use FireflyIII\Support\Form\FormSupport; | 
					
						
							| 
									
										
										
										
											2018-04-29 09:48:53 +02:00
										 |  |  | use Form; | 
					
						
							| 
									
										
										
										
											2015-02-24 21:10:25 +01:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2018-07-27 05:03:37 +02:00
										 |  |  | use Illuminate\Support\HtmlString; | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | use Illuminate\Support\MessageBag; | 
					
						
							| 
									
										
										
										
											2018-07-02 15:37:56 +02:00
										 |  |  | use Log; | 
					
						
							| 
									
										
										
										
											2015-06-07 15:32:01 +02:00
										 |  |  | use RuntimeException; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  | use Throwable; | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class ExpandedForm. | 
					
						
							| 
									
										
										
										
											2018-07-15 10:00:08 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-28 10:45:16 +02:00
										 |  |  |  * @SuppressWarnings(PHPMD.TooManyMethods) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.TooManyPublicMethods) | 
					
						
							| 
									
										
										
										
											2019-07-31 16:53:09 +02:00
										 |  |  |  * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | class ExpandedForm | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-10 15:09:44 +02:00
										 |  |  |     use FormSupport; | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-03-11 16:24:07 +01:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2018-04-07 22:23:16 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-04-07 22:23:16 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function amountNoCurrency(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2018-04-07 22:23:16 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |         $options         = $options ?? []; | 
					
						
							| 
									
										
										
										
											2018-04-07 22:23:16 +02:00
										 |  |  |         $label           = $this->label($name, $options); | 
					
						
							|  |  |  |         $options         = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes         = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value           = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['step'] = 'any'; | 
					
						
							|  |  |  |         unset($options['currency'], $options['placeholder']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // make sure value is formatted nicely:
 | 
					
						
							|  |  |  |         if (null !== $value && '' !== $value) { | 
					
						
							|  |  |  |             $value = round($value, 8); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.amount-no-currency', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render amountNoCurrency.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-04-07 22:23:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param int $value | 
					
						
							|  |  |  |      * @param mixed $checked | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function checkbox(string $name, int $value = null, $checked = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |         $options            = $options ?? []; | 
					
						
							|  |  |  |         $value              = $value ?? 1; | 
					
						
							| 
									
										
										
										
											2018-07-27 05:03:37 +02:00
										 |  |  |         $options['checked'] = true === $checked; | 
					
						
							| 
									
										
										
										
											2018-04-22 11:29:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |         if (app('session')->has('preFilled')) { | 
					
						
							| 
									
										
										
										
											2018-04-22 11:29:20 +02:00
										 |  |  |             $preFilled          = session('preFilled'); | 
					
						
							|  |  |  |             $options['checked'] = $preFilled[$name] ?? $options['checked']; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value   = $this->fillFieldValue($name, $value); | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         unset($options['placeholder'], $options['autocomplete'], $options['class']); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render checkbox(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render checkbox.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function date(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value   = $this->fillFieldValue($name, $value); | 
					
						
							| 
									
										
										
										
											2015-06-22 18:50:54 +02:00
										 |  |  |         unset($options['placeholder']); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render date(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render date.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function file(string $name, array $options = null): string | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |         $options = $options ?? []; | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.file', compact('classes', 'name', 'label', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render file(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render file.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-03 22:54:21 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-04-03 22:54:21 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-04-03 22:54:21 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function integer(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-04-03 22:54:21 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |         $options         = $options ?? []; | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |         $label           = $this->label($name, $options); | 
					
						
							|  |  |  |         $options         = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes         = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value           = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['step'] = '1'; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render integer(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render integer.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-04-03 22:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function location(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |         $options = $options ?? []; | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value   = $this->fillFieldValue($name, $value); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.location', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render location(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render location.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 19:21:47 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-04-29 17:29:13 +02:00
										 |  |  |      * @param \Illuminate\Support\Collection $set | 
					
						
							| 
									
										
										
										
											2016-04-27 19:21:47 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							| 
									
										
										
										
											2018-07-28 10:45:16 +02:00
										 |  |  |      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | 
					
						
							| 
									
										
										
										
											2016-04-27 19:21:47 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function makeSelectListWithEmpty(Collection $set): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-20 08:00:35 +02:00
										 |  |  |         $selectList    = []; | 
					
						
							| 
									
										
										
										
											2016-04-27 19:21:47 +02:00
										 |  |  |         $selectList[0] = '(none)'; | 
					
						
							|  |  |  |         $fields        = ['title', 'name', 'description']; | 
					
						
							| 
									
										
										
										
											2015-03-07 09:21:06 +01:00
										 |  |  |         /** @var Eloquent $entry */ | 
					
						
							| 
									
										
										
										
											2015-02-24 21:10:25 +01:00
										 |  |  |         foreach ($set as $entry) { | 
					
						
							| 
									
										
										
										
											2018-04-02 14:50:17 +02:00
										 |  |  |             $entryId = (int)$entry->id; | 
					
						
							| 
									
										
										
										
											2015-05-25 07:14:04 +02:00
										 |  |  |             $title   = null; | 
					
						
							| 
									
										
										
										
											2015-02-24 21:10:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             foreach ($fields as $field) { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |                 if (isset($entry->$field) && null === $title) { | 
					
						
							| 
									
										
										
										
											2015-02-24 21:10:25 +01:00
										 |  |  |                     $title = $entry->$field; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-05-25 07:14:04 +02:00
										 |  |  |             $selectList[$entryId] = $title; | 
					
						
							| 
									
										
										
										
											2015-02-24 21:10:25 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $selectList; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-14 07:11:30 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2017-04-14 07:11:30 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function nonSelectableAmount(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2017-04-14 07:11:30 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-14 10:16:52 +02:00
										 |  |  |         $label            = $this->label($name, $options); | 
					
						
							|  |  |  |         $options          = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes          = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value            = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['step']  = 'any'; | 
					
						
							| 
									
										
										
										
											2018-04-02 14:50:17 +02:00
										 |  |  |         $selectedCurrency = $options['currency'] ?? Amt::getDefaultCurrency(); | 
					
						
							| 
									
										
										
										
											2018-03-29 19:01:47 +02:00
										 |  |  |         unset($options['currency'], $options['placeholder']); | 
					
						
							| 
									
										
										
										
											2017-04-14 10:16:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // make sure value is formatted nicely:
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (null !== $value && '' !== $value) { | 
					
						
							| 
									
										
										
										
											2017-04-14 10:16:52 +02:00
										 |  |  |             $value = round($value, $selectedCurrency->decimal_places); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.non-selectable-amount', compact('selectedCurrency', 'classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render nonSelectableAmount(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render nonSelectableAmount.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-04-14 10:16:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-03 06:58:39 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2017-11-03 06:58:39 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-11-03 06:58:39 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function number(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2017-11-03 06:58:39 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $label           = $this->label($name, $options); | 
					
						
							|  |  |  |         $options         = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes         = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value           = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['step'] = 'any'; | 
					
						
							|  |  |  |         unset($options['placeholder']); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.number', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render number(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render number.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-03 06:58:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:47 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |      * @param string $type | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:47 +02:00
										 |  |  |      * @param string $name | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |     public function optionsList(string $type, string $name): string | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:47 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         try { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             $html = view('form.options', compact('type', 'name'))->render(); | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:47 +02:00
										 |  |  |         } catch (Throwable $e) { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             Log::debug(sprintf('Could not render select(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render optionsList.'; | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:47 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |     public function password(string $name, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             $html = view('form.password', compact('classes', 'name', 'label', 'options'))->render(); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         } catch (Throwable $e) { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             Log::debug(sprintf('Could not render password(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render password.'; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-04-25 18:43:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 17:14:43 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |      * Function to render a percentage. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2016-12-20 17:14:43 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-12-20 17:14:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |     public function percentage(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2016-12-20 17:14:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |         $label           = $this->label($name, $options); | 
					
						
							|  |  |  |         $options         = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes         = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value           = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['step'] = 'any'; | 
					
						
							|  |  |  |         unset($options['placeholder']); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             $html = view('form.percentage', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         } catch (Throwable $e) { | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  |             Log::debug(sprintf('Could not render percentage(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render percentage.'; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-20 17:14:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function staticText(string $name, $value, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-01-20 15:23:36 +01:00
										 |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render staticText(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render staticText.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function text(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $label   = $this->label($name, $options); | 
					
						
							|  |  |  |         $options = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value   = $this->fillFieldValue($name, $value); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render text(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render text.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-08 01:15:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2019-06-22 10:25:57 +02:00
										 |  |  |      * @param mixed $value | 
					
						
							|  |  |  |      * @param array $options | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-23 21:49:15 +02:00
										 |  |  |     public function textarea(string $name, $value = null, array $options = null): string | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $label           = $this->label($name, $options); | 
					
						
							|  |  |  |         $options         = $this->expandOptionArray($name, $label, $options); | 
					
						
							|  |  |  |         $classes         = $this->getHolderClasses($name); | 
					
						
							|  |  |  |         $value           = $this->fillFieldValue($name, $value); | 
					
						
							|  |  |  |         $options['rows'] = 4; | 
					
						
							| 
									
										
										
										
											2018-08-05 18:59:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (null === $value) { | 
					
						
							|  |  |  |             $value = ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 21:12:48 +02:00
										 |  |  |         try { | 
					
						
							|  |  |  |             $html = view('form.textarea', compact('classes', 'name', 'label', 'value', 'options'))->render(); | 
					
						
							|  |  |  |         } catch (Throwable $e) { | 
					
						
							|  |  |  |             Log::debug(sprintf('Could not render textarea(): %s', $e->getMessage())); | 
					
						
							|  |  |  |             $html = 'Could not render textarea.'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-04-28 08:58:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $html; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-03-29 08:14:32 +02:00
										 |  |  | } |