Passed
Branch master (350f1b)
by Jan
04:53
created

Supplier::getIDString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
 * part-db version 0.1
25
 * Copyright (C) 2005 Christoph Lechner
26
 * http://www.cl-projects.de/.
27
 *
28
 * part-db version 0.2+
29
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
30
 * http://code.google.com/p/part-db/
31
 *
32
 * Part-DB Version 0.4+
33
 * Copyright (C) 2016 - 2019 Jan Böhmer
34
 * https://github.com/jbtronics
35
 *
36
 * This program is free software; you can redistribute it and/or
37
 * modify it under the terms of the GNU General Public License
38
 * as published by the Free Software Foundation; either version 2
39
 * of the License, or (at your option) any later version.
40
 *
41
 * This program is distributed in the hope that it will be useful,
42
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44
 * GNU General Public License for more details.
45
 *
46
 * You should have received a copy of the GNU General Public License
47
 * along with this program; if not, write to the Free Software
48
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
49
 */
50
51
namespace App\Entity\Parts;
52
53
use App\Entity\Attachments\SupplierAttachment;
54
use App\Entity\Base\AbstractCompany;
55
use App\Entity\Parameters\SupplierParameter;
56
use App\Entity\PriceInformations\Currency;
57
use App\Validator\Constraints\Selectable;
58
use Doctrine\Common\Collections\Collection;
59
use Doctrine\ORM\Mapping as ORM;
60
use Symfony\Component\Validator\Constraints as Assert;
61
62
/**
63
 * Class Supplier.
64
 *
65
 * @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
66
 * @ORM\Table("`suppliers`")
67
 */
68
class Supplier extends AbstractCompany
69
{
70
    /**
71
     * @ORM\OneToMany(targetEntity="Supplier", mappedBy="parent")
72
     * @ORM\OrderBy({"name" = "ASC"})
73
     */
74
    protected $children;
75
76
    /**
77
     * @ORM\ManyToOne(targetEntity="Supplier", inversedBy="children")
78
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
79
     */
80
    protected $parent;
81
82
    /**
83
     * @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="supplier")
84
     */
85
    protected $orderdetails;
86
87
    /**
88
     * @var Currency|null The currency that should be used by default for order informations with this supplier.
89
     *                    Set to null, to use global base currency.
90
     * @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency")
91
     * @ORM\JoinColumn(name="default_currency_id", referencedColumnName="id", nullable=true)
92
     * @Selectable()
93
     */
94
    protected $default_currency;
95
96
    /**
97
     * @var string|null the shipping costs that have to be paid, when ordering via this supplier
98
     * @ORM\Column(name="shipping_costs", nullable=true, type="decimal", precision=11, scale=5)
99
     * @Assert\PositiveOrZero()
100
     */
101
    protected $shipping_costs;
102
103
    /**
104
     * @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
105
     * @ORM\JoinTable(name="orderdetails",
106
     *     joinColumns={@ORM\JoinColumn(name="id_supplier", referencedColumnName="id")},
107
     *     inverseJoinColumns={@ORM\JoinColumn(name="part_id", referencedColumnName="id")}
108
     * )
109
     */
110
    protected $parts;
111
112
    /**
113
     * @var Collection<int, SupplierAttachment>
114
     * @ORM\OneToMany(targetEntity="App\Entity\Attachments\SupplierAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
115
     * @ORM\OrderBy({"name" = "ASC"})
116
     * @Assert\Valid()
117
     */
118
    protected $attachments;
119
120
    /** @var Collection<int, SupplierParameter>
121
     * @ORM\OneToMany(targetEntity="App\Entity\Parameters\SupplierParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
122
     * @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
123
     * @Assert\Valid()
124
     */
125
    protected $parameters;
126
127
    /**
128
     * Gets the currency that should be used by default, when creating a orderdetail with this supplier.
129
     *
130
     * @return Currency|null
131
     */
132
    public function getDefaultCurrency(): ?Currency
133
    {
134
        return $this->default_currency;
135
    }
136
137
    /**
138
     * Sets the default currency.
139
     *
140
     * @return Supplier
141
     */
142
    public function setDefaultCurrency(?Currency $default_currency): self
143
    {
144
        $this->default_currency = $default_currency;
145
146
        return $this;
147
    }
148
149
    /**
150
     * Gets the shipping costs for an order with this supplier, given in base currency.
151
     *
152
     * @return string|null A bcmath string with the shipping costs
153
     */
154
    public function getShippingCosts(): ?string
155
    {
156
        return $this->shipping_costs;
157
    }
158
159
    /**
160
     * Sets the shipping costs for an order with this supplier.
161
     *
162
     * @param string|null $shipping_costs a bcmath string with the shipping costs
163
     *
164
     * @return Supplier
165
     */
166
    public function setShippingCosts(?string $shipping_costs): self
167
    {
168
        /* Just a little hack to ensure that price has 5 digits after decimal point,
169
         so that DB does not detect changes, when something like 0.4 is passed
170
         Third parameter must have the scale value of decimal column. */
171
        $this->shipping_costs = bcmul($shipping_costs, '1.0', 5);
172
173
        return $this;
174
    }
175
}
176