1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace App\Entity\PriceInformations; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use App\Entity\Base\StructuralDBElement; |
36
|
|
|
use Doctrine\ORM\Mapping as ORM; |
37
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
38
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* This entity describes a currency that can be used for price informations. |
42
|
|
|
* @package App\Entity |
43
|
|
|
* @UniqueEntity("iso_code") |
44
|
|
|
* @ORM\Entity() |
45
|
|
|
* @ORM\Table(name="currencies") |
46
|
|
|
*/ |
47
|
|
|
class Currency extends StructuralDBElement |
48
|
|
|
{ |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string The 3 letter ISO code of the currency. |
52
|
|
|
* @ORM\Column(type="string", unique=true, nullable=true) |
53
|
|
|
* @Assert\Currency() |
54
|
|
|
*/ |
55
|
|
|
protected $iso_code; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var float|null The exchange rate between this currency and the base currency |
59
|
|
|
* (how many base units the current currency is worth) |
60
|
|
|
* @ORM\Column(type="decimal", precision=11, scale=5) |
61
|
|
|
* @Assert\Positive() |
62
|
|
|
*/ |
63
|
|
|
protected $exchange_rate; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the 3 letter ISO code of this currency |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getIsoCode(): string |
70
|
|
|
{ |
71
|
|
|
return $this->iso_code; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $iso_code |
76
|
|
|
* @return Currency |
77
|
|
|
*/ |
78
|
|
|
public function setIsoCode(string $iso_code): Currency |
79
|
|
|
{ |
80
|
|
|
$this->iso_code = $iso_code; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the inverse exchange rate (how many of the current currency the base unit is worth) |
86
|
|
|
* @return float|null |
87
|
|
|
*/ |
88
|
|
|
public function getInverseExchangeRate(): ?float |
89
|
|
|
{ |
90
|
|
|
$tmp = $this->getExchangeRate(); |
91
|
|
|
|
92
|
|
|
if ($tmp == null) { |
93
|
|
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return 1 / $tmp; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns The exchange rate between this currency and the base currency |
101
|
|
|
* (how many base units the current currency is worth) |
102
|
|
|
* @return float|null |
103
|
|
|
*/ |
104
|
|
|
public function getExchangeRate(): ?float |
105
|
|
|
{ |
106
|
|
|
return $this->exchange_rate; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param float|null $exchange_rate |
111
|
|
|
* @return Currency |
112
|
|
|
*/ |
113
|
|
|
public function setExchangeRate(?float $exchange_rate): Currency |
114
|
|
|
{ |
115
|
|
|
$this->exchange_rate = $exchange_rate; |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the ID as an string, defined by the element class. |
122
|
|
|
* This should have a form like P000014, for a part with ID 14. |
123
|
|
|
* |
124
|
|
|
* @return string The ID as a string; |
125
|
|
|
* |
126
|
|
|
*/ |
127
|
|
|
public function getIDString(): string |
128
|
|
|
{ |
129
|
|
|
return 'C' . $this->getID(); |
130
|
|
|
} |
131
|
|
|
} |