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