Failed Conditions
Push — master ( ebbcf8...65b05b )
by Sylvain
09:05
created

ExpenseClaim::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\DBAL\Types\ExpenseClaimStatusType;
8
use Application\DBAL\Types\ExpenseClaimTypeType;
9
use Application\Traits\HasRemarks;
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\Mapping as ORM;
13
use Ecodev\Felix\Model\Traits\HasDescription;
14
use Ecodev\Felix\Model\Traits\HasInternalRemarks;
15
use Ecodev\Felix\Model\Traits\HasName;
16
use GraphQL\Doctrine\Annotation as API;
17
use Money\Money;
18
19
/**
20
 * An expense claim to be refunded to a member or invoice to be paid by the company
21
 *
22
 * @ORM\Entity(repositoryClass="Application\Repository\ExpenseClaimRepository")
23
 * @ORM\AssociationOverrides({
24
 *     @ORM\AssociationOverride(
25
 *         name="owner",
26
 *         joinColumns=@ORM\JoinColumn(nullable=false, onDelete="CASCADE")
27
 *     )
28
 * })
29
 * @API\Filters({
30
 *     @API\Filter(field="custom", operator="Application\Api\Input\Operator\ExpenseClaimToReviewOperatorType", type="boolean"),
31
 * })
32
 */
33
class ExpenseClaim extends AbstractModel
34
{
35
    use HasName;
36
    use HasDescription;
37
    use HasRemarks;
38
    use HasInternalRemarks;
39
40
    /**
41
     * @var Money
42
     *
43
     * @ORM\Column(type="Money", options={"unsigned" = true})
44
     */
45
    private $amount;
46
47
    /**
48
     * @var Collection
49
     * @ORM\OneToMany(targetEntity="Transaction", mappedBy="expenseClaim")
50
     */
51
    private $transactions;
52
53
    /**
54
     * @var Collection
55
     * @ORM\OneToMany(targetEntity="AccountingDocument", mappedBy="expenseClaim")
56
     */
57
    private $accountingDocuments;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(type="ExpenseClaimStatus", length=10, options={"default" = ExpenseClaimStatusType::NEW})
63
     */
64
    private $status = ExpenseClaimStatusType::NEW;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(type="ExpenseClaimType", length=10, options={"default" = ExpenseClaimTypeType::EXPENSE_CLAIM})
70
     */
71
    private $type = ExpenseClaimTypeType::EXPENSE_CLAIM;
72
73
    /**
74
     * @var null|User
75
     *
76
     * @ORM\ManyToOne(targetEntity="User")
77
     * @ORM\JoinColumns({
78
     *     @ORM\JoinColumn(onDelete="SET NULL")
79
     * })
80
     */
81
    private $reviewer;
82
83
    /**
84
     * @ORM\Column(type="string", length=191, options={"default" = ""})
85
     *
86
     * @var string
87
     */
88
    private $sector = '';
89
90
    /**
91
     * Constructor
92
     */
93 8
    public function __construct()
94
    {
95 8
        $this->transactions = new ArrayCollection();
96 8
        $this->accountingDocuments = new ArrayCollection();
97 8
    }
98
99
    /**
100
     * Set amount
101
     */
102 1
    public function setAmount(Money $amount): void
103
    {
104 1
        $this->amount = $amount;
105 1
    }
106
107
    /**
108
     * Get amount
109
     */
110
    public function getAmount(): Money
111
    {
112
        return $this->amount;
113
    }
114
115
    /**
116
     * Set status
117
     *
118
     * @API\Input(type="ExpenseClaimStatus")
119
     */
120 3
    public function setStatus(string $status): void
121
    {
122 3
        $this->status = $status;
123 3
    }
124
125
    /**
126
     * Get status
127
     *
128
     * @API\Field(type="ExpenseClaimStatus")
129
     */
130 5
    public function getStatus(): string
131
    {
132 5
        return $this->status;
133
    }
134
135
    /**
136
     * Set type
137
     *
138
     * @API\Input(type="ExpenseClaimType")
139
     */
140
    public function setType(string $type): void
141
    {
142
        $this->type = $type;
143
    }
144
145
    /**
146
     * Get type
147
     *
148
     * @API\Field(type="ExpenseClaimType")
149
     */
150
    public function getType(): string
151
    {
152
        return $this->type;
153
    }
154
155
    /**
156
     * Notify the expense claim that a transaction was added
157
     * This should only be called by Transaction::setExpenseClaim()
158
     */
159 1
    public function transactionAdded(Transaction $transaction): void
160
    {
161 1
        $this->transactions->add($transaction);
162 1
        $this->status = ExpenseClaimStatusType::PROCESSED;
163 1
    }
164
165
    /**
166
     * Notify the expense claim that a transaction was removed
167
     * This should only be called by Transaction::setExpenseClaim()
168
     */
169 1
    public function transactionRemoved(Transaction $transaction): void
170
    {
171 1
        $this->transactions->removeElement($transaction);
172 1
    }
173
174
    /**
175
     * Get the transactions created from this expense claim
176
     */
177 1
    public function getTransactions(): Collection
178
    {
179 1
        return $this->transactions;
180
    }
181
182
    /**
183
     * Notify the expense that an accounting document was added
184
     * This should only be called by AccountingDocument::setExpenseClaim()
185
     */
186 7
    public function accountingDocumentAdded(AccountingDocument $document): void
187
    {
188 7
        $this->accountingDocuments->add($document);
189 7
    }
190
191
    /**
192
     * Notify the expense that an accounting document was removed
193
     * This should only be called by AccountingDocument::setExpenseClaim()
194
     */
195 1
    public function accountingDocumentRemoved(AccountingDocument $document): void
196
    {
197 1
        $this->accountingDocuments->removeElement($document);
198 1
    }
199
200
    /**
201
     * Get accounting documents
202
     */
203 1
    public function getAccountingDocuments(): Collection
204
    {
205 1
        return $this->accountingDocuments;
206
    }
207
208
    /**
209
     * Set reviewer
210
     */
211
    public function setReviewer(?User $reviewer): void
212
    {
213
        $this->reviewer = $reviewer;
214
    }
215
216
    /**
217
     * Get reviewer
218
     */
219
    public function getReviewer(): ?User
220
    {
221
        return $this->reviewer;
222
    }
223
224
    /**
225
     * Set sector
226
     */
227
    public function setSector(string $sector): void
228
    {
229
        $this->sector = $sector;
230
    }
231
232
    /**
233
     * Get sector
234
     */
235
    public function getSector(): string
236
    {
237
        return (string) $this->sector;
238
    }
239
}
240