1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\Traits\HasAutomaticBalance; |
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Doctrine\Common\Collections\Collection; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
use GraphQL\Doctrine\Annotation as API; |
12
|
|
|
use Money\Money; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* An order made by a users |
16
|
|
|
* |
17
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\OrderRepository") |
18
|
|
|
* @ORM\Table(name="`order`") |
19
|
|
|
*/ |
20
|
|
|
class Order extends AbstractModel |
21
|
|
|
{ |
22
|
|
|
const STATUS_PENDING = 'pending'; |
23
|
|
|
const STATUS_VALIDATED = 'validated'; |
24
|
|
|
|
25
|
|
|
use HasAutomaticBalance; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Collection |
29
|
|
|
* @ORM\OneToMany(targetEntity="OrderLine", mappedBy="order") |
30
|
|
|
*/ |
31
|
|
|
private $orderLines; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
* @ORM\Column(type="OrderStatus", options={"default" = Order::STATUS_PENDING}) |
36
|
|
|
*/ |
37
|
|
|
private $status = self::STATUS_PENDING; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor |
41
|
|
|
* |
42
|
|
|
* @param string $status status for new order |
43
|
|
|
*/ |
44
|
9 |
|
public function __construct(string $status = self::STATUS_PENDING) |
45
|
|
|
{ |
46
|
9 |
|
$this->status = $status; |
47
|
9 |
|
$this->orderLines = new ArrayCollection(); |
48
|
9 |
|
$this->balanceCHF = Money::CHF(0); |
49
|
9 |
|
$this->balanceEUR = Money::EUR(0); |
50
|
9 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Notify when a order line is added |
54
|
|
|
* This should only be called by OrderLine::setOrder() |
55
|
|
|
* |
56
|
|
|
* @param OrderLine $orderLine |
57
|
|
|
*/ |
58
|
9 |
|
public function orderLineAdded(OrderLine $orderLine): void |
59
|
|
|
{ |
60
|
9 |
|
$this->orderLines->add($orderLine); |
61
|
9 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Notify when a order line is removed |
65
|
|
|
* This should only be called by OrderLine::setOrder() |
66
|
|
|
* |
67
|
|
|
* @param OrderLine $orderLine |
68
|
|
|
*/ |
69
|
1 |
|
public function orderLineRemoved(OrderLine $orderLine): void |
70
|
|
|
{ |
71
|
1 |
|
$this->orderLines->removeElement($orderLine); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Collection |
76
|
|
|
*/ |
77
|
9 |
|
public function getOrderLines(): Collection |
78
|
|
|
{ |
79
|
9 |
|
return $this->orderLines; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @API\Field(type="Application\Api\Enum\OrderStatusType") |
84
|
|
|
*/ |
85
|
|
|
public function getStatus(): string |
86
|
|
|
{ |
87
|
|
|
return $this->status; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $status |
92
|
|
|
*/ |
93
|
|
|
public function setStatus(string $status): void |
94
|
|
|
{ |
95
|
|
|
$this->status = $status; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|