|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
25
|
|
|
* |
|
26
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
|
27
|
|
|
* |
|
28
|
|
|
* This program is free software; you can redistribute it and/or |
|
29
|
|
|
* modify it under the terms of the GNU General Public License |
|
30
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
31
|
|
|
* of the License, or (at your option) any later version. |
|
32
|
|
|
* |
|
33
|
|
|
* This program is distributed in the hope that it will be useful, |
|
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
36
|
|
|
* GNU General Public License for more details. |
|
37
|
|
|
* |
|
38
|
|
|
* You should have received a copy of the GNU General Public License |
|
39
|
|
|
* along with this program; if not, write to the Free Software |
|
40
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
41
|
|
|
*/ |
|
42
|
|
|
|
|
43
|
|
|
namespace App\Form\AdminPages; |
|
44
|
|
|
|
|
45
|
|
|
use App\Entity\Base\AbstractNamedDBElement; |
|
46
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CurrencyType; |
|
47
|
|
|
use Symfony\Component\Form\Extension\Core\Type\MoneyType; |
|
48
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
49
|
|
|
use Symfony\Component\Security\Core\Security; |
|
50
|
|
|
|
|
51
|
|
|
class CurrencyAdminForm extends BaseEntityAdminForm |
|
52
|
|
|
{ |
|
53
|
|
|
private $default_currency; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct(Security $security, string $default_currency) |
|
56
|
|
|
{ |
|
57
|
|
|
parent::__construct($security); |
|
58
|
|
|
$this->default_currency = $default_currency; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void |
|
62
|
|
|
{ |
|
63
|
|
|
$is_new = null === $entity->getID(); |
|
64
|
|
|
|
|
65
|
|
|
$builder->add('iso_code', CurrencyType::class, [ |
|
66
|
|
|
'required' => false, |
|
67
|
|
|
'label' => 'currency.edit.iso_code', |
|
68
|
|
|
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'], |
|
69
|
|
|
'attr' => [ |
|
70
|
|
|
'class' => 'selectpicker', |
|
71
|
|
|
'title' => 'selectpicker.nothing_selected', |
|
72
|
|
|
'data-live-search' => true, |
|
73
|
|
|
], |
|
74
|
|
|
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
|
75
|
|
|
]); |
|
76
|
|
|
|
|
77
|
|
|
$builder->add('exchange_rate', MoneyType::class, [ |
|
78
|
|
|
'required' => false, |
|
79
|
|
|
'label' => 'currency.edit.exchange_rate', |
|
80
|
|
|
'currency' => $this->default_currency, |
|
81
|
|
|
'scale' => 6, |
|
82
|
|
|
'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|