ExpenseClaim::getStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Api\Input\Operator\ExpenseClaimToReviewOperatorType;
8
use Application\Enum\ExpenseClaimStatus;
9
use Application\Enum\ExpenseClaimType;
10
use Application\Repository\ExpenseClaimRepository;
11
use Application\Traits\HasRemarks;
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Doctrine\Common\Collections\Collection;
14
use Doctrine\ORM\Mapping as ORM;
15
use Ecodev\Felix\Model\Traits\HasDescription;
16
use Ecodev\Felix\Model\Traits\HasInternalRemarks;
17
use Ecodev\Felix\Model\Traits\HasName;
18
use GraphQL\Doctrine\Attribute as API;
19
use Money\Money;
20
21
/**
22
 * An expense claim to be refunded to a member or invoice to be paid by the company.
23
 */
24
#[API\Filter(field: 'custom', operator: ExpenseClaimToReviewOperatorType::class, type: 'boolean')]
25
#[ORM\Entity(ExpenseClaimRepository::class)]
26
class ExpenseClaim extends AbstractModel
27
{
28
    use HasDescription;
29
    use HasInternalRemarks;
30
    use HasName;
31
    use HasRemarks;
32
33
    #[ORM\Column(type: 'Money', options: ['unsigned' => true])]
34
    private Money $amount;
35
36
    /**
37
     * @var Collection<int, Transaction>
38
     */
39
    #[ORM\OneToMany(targetEntity: Transaction::class, mappedBy: 'expenseClaim')]
40
    private Collection $transactions;
41
42
    /**
43
     * @var Collection<int, AccountingDocument>
44
     */
45
    #[ORM\OneToMany(targetEntity: AccountingDocument::class, mappedBy: 'expenseClaim')]
46
    private Collection $accountingDocuments;
47
48
    #[ORM\Column(type: 'enum', length: 10, options: ['default' => ExpenseClaimStatus::New])]
49
    private ExpenseClaimStatus $status = ExpenseClaimStatus::New;
50
51
    #[ORM\Column(type: 'enum', length: 10, options: ['default' => ExpenseClaimType::ExpenseClaim])]
52
    private ExpenseClaimType $type = ExpenseClaimType::ExpenseClaim;
53
54
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
55
    #[ORM\ManyToOne(targetEntity: User::class)]
56
    private ?User $reviewer = null;
57
58
    #[ORM\Column(type: 'string', length: 191, options: ['default' => ''])]
59
    private string $sector = '';
60
61 8
    public function __construct()
62
    {
63 8
        $this->transactions = new ArrayCollection();
64 8
        $this->accountingDocuments = new ArrayCollection();
65
    }
66
67
    /**
68
     * Set amount.
69
     */
70 1
    public function setAmount(Money $amount): void
71
    {
72 1
        $this->amount = $amount;
73
    }
74
75
    /**
76
     * Get amount.
77
     */
78
    public function getAmount(): Money
79
    {
80
        return $this->amount;
81
    }
82
83
    /**
84
     * Set status.
85
     */
86 3
    public function setStatus(ExpenseClaimStatus $status): void
87
    {
88 3
        $this->status = $status;
89
    }
90
91
    /**
92
     * Get status.
93
     */
94 5
    public function getStatus(): ExpenseClaimStatus
95
    {
96 5
        return $this->status;
97
    }
98
99
    /**
100
     * Set type.
101
     */
102
    public function setType(ExpenseClaimType $type): void
103
    {
104
        $this->type = $type;
105
    }
106
107
    /**
108
     * Get type.
109
     */
110
    public function getType(): ExpenseClaimType
111
    {
112
        return $this->type;
113
    }
114
115
    /**
116
     * Notify the expense claim that a transaction was added
117
     * This should only be called by Transaction::setExpenseClaim().
118
     */
119 1
    public function transactionAdded(Transaction $transaction): void
120
    {
121 1
        $this->transactions->add($transaction);
122 1
        $this->status = ExpenseClaimStatus::Processed;
123
    }
124
125
    /**
126
     * Notify the expense claim that a transaction was removed
127
     * This should only be called by Transaction::setExpenseClaim().
128
     */
129 1
    public function transactionRemoved(Transaction $transaction): void
130
    {
131 1
        $this->transactions->removeElement($transaction);
132
    }
133
134
    /**
135
     * Get the transactions created from this expense claim.
136
     */
137 1
    public function getTransactions(): Collection
138
    {
139 1
        return $this->transactions;
140
    }
141
142
    /**
143
     * Notify the expense that an accounting document was added
144
     * This should only be called by AccountingDocument::setExpenseClaim().
145
     */
146 7
    public function accountingDocumentAdded(AccountingDocument $document): void
147
    {
148 7
        $this->accountingDocuments->add($document);
149
    }
150
151
    /**
152
     * Notify the expense that an accounting document was removed
153
     * This should only be called by AccountingDocument::setExpenseClaim().
154
     */
155 1
    public function accountingDocumentRemoved(AccountingDocument $document): void
156
    {
157 1
        $this->accountingDocuments->removeElement($document);
158
    }
159
160
    /**
161
     * Get accounting documents.
162
     */
163 1
    public function getAccountingDocuments(): Collection
164
    {
165 1
        return $this->accountingDocuments;
166
    }
167
168
    /**
169
     * Set reviewer.
170
     */
171
    public function setReviewer(?User $reviewer): void
172
    {
173
        $this->reviewer = $reviewer;
174
    }
175
176
    /**
177
     * Get reviewer.
178
     */
179
    public function getReviewer(): ?User
180
    {
181
        return $this->reviewer;
182
    }
183
184
    /**
185
     * Set sector.
186
     */
187
    public function setSector(string $sector): void
188
    {
189
        $this->sector = $sector;
190
    }
191
192
    /**
193
     * Get sector.
194
     */
195
    public function getSector(): string
196
    {
197
        return (string) $this->sector;
198
    }
199
}
200