Passed
Push — master ( 25de29...525d98 )
by Sam
10:52
created

TransactionLine::getBookable()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Traits\HasName;
8
use Application\Traits\HasRemarks;
9
use Cake\Chronos\Chronos;
10
use Doctrine\ORM\Mapping as ORM;
11
use GraphQL\Doctrine\Annotation as API;
12
use Money\Money;
13
14
/**
15
 * A single line of accounting transaction
16
 *
17
 * @ORM\Entity(repositoryClass="Application\Repository\TransactionLineRepository")
18
 * @API\Filters({
19
 *     @API\Filter(field="custom", operator="Application\Api\Input\Operator\TransactionExportOperatorType", type="boolean"),
20
 * })
21
 */
22
class TransactionLine extends AbstractModel
23
{
24
    use HasName;
25
    use HasRemarks;
26
27
    /**
28
     * @var Transaction
29
     *
30
     * @ORM\ManyToOne(targetEntity="Transaction", inversedBy="transactionLines")
31
     * @ORM\JoinColumns({
32
     *     @ORM\JoinColumn(nullable=false, onDelete="RESTRICT")
33
     * })
34
     */
35
    private $transaction;
36
37
    /**
38
     * @var null|Account
39
     *
40
     * @ORM\ManyToOne(targetEntity="Account", inversedBy="debitTransactionLines")
41
     * @ORM\JoinColumns({
42
     *     @ORM\JoinColumn(nullable=true, onDelete="RESTRICT")
43
     * })
44
     */
45
    private $debit;
46
47
    /**
48
     * @var null|Account
49
     *
50
     * @ORM\ManyToOne(targetEntity="Account", inversedBy="creditTransactionLines")
51
     * @ORM\JoinColumns({
52
     *     @ORM\JoinColumn(nullable=true, onDelete="RESTRICT")
53
     * })
54
     */
55
    private $credit;
56
57
    /**
58
     * @var null|Bookable
59
     *
60
     * @ORM\ManyToOne(targetEntity="Bookable")
61
     * @ORM\JoinColumns({
62
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
63
     * })
64
     */
65
    private $bookable;
66
67
    /**
68
     * @var Money
69
     *
70
     * @ORM\Column(type="Money", options={"unsigned" = true})
71
     */
72
    private $balance;
73
74
    /**
75
     * @var Chronos
76
     * @ORM\Column(type="datetime")
77
     */
78
    private $transactionDate;
79
80
    /**
81
     * @var null|TransactionTag
82
     *
83
     * @ORM\ManyToOne(targetEntity="TransactionTag")
84
     * @ORM\JoinColumns({
85
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
86
     * })
87
     */
88
    private $transactionTag;
89
90
    /**
91
     * @var bool
92
     *
93
     * @ORM\Column(type="boolean", options={"default" = 0})
94
     */
95
    private $isReconciled = false;
96
97
    /**
98
     * This store the value of CAMT 054 `<AcctSvcrRef>` element that should
99
     * hopefully be a universally unique transaction identifier.
100
     *
101
     * An absence of value means the line was not imported.
102
     *
103
     * @var null|string
104
     * @ORM\Column(type="string", length=35, nullable=true, unique=true)
105
     */
106
    private $importedId;
107
108
    /**
109
     * Set importedId
110
     *
111
     * @API\Exclude
112
     *
113
     * @param string $importedId
114
     */
115 3
    public function setImportedId(string $importedId): void
116
    {
117 3
        $this->importedId = $importedId;
118 3
    }
119
120
    /**
121
     * Get importedId
122
     *
123
     * @return null|string
124
     */
125 2
    public function getImportedId(): ?string
126
    {
127 2
        return $this->importedId;
128
    }
129
130
    /**
131
     * @API\Exclude
132
     *
133
     * @param Transaction $transaction
134
     */
135 17
    public function setTransaction(Transaction $transaction): void
136
    {
137 17
        if ($this->transaction) {
138 1
            $this->transaction->transactionLineRemoved($this);
139
        }
140
141 17
        $this->transaction = $transaction;
142 17
        $transaction->transactionLineAdded($this);
143 17
    }
144
145
    /**
146
     * @return Transaction
147
     */
148 4
    public function getTransaction(): Transaction
149
    {
150 4
        return $this->transaction;
151
    }
152
153
    /**
154
     * Set debit account
155
     *
156
     * @param null|Account $account
157
     */
158 17
    public function setDebit(?Account $account): void
159
    {
160 17
        if ($this->debit) {
161 1
            $this->debit->debitTransactionLineRemoved($this);
162
        }
163
164 17
        $this->debit = $account;
165
166 17
        if ($this->debit) {
167 17
            $this->debit->debitTransactionLineAdded($this);
168
        }
169 17
    }
170
171
    /**
172
     * Get debit account
173
     *
174
     * @return null|Account
175
     */
176 14
    public function getDebit(): ?Account
177
    {
178 14
        return $this->debit;
179
    }
180
181
    /**
182
     * Set credit account
183
     *
184
     * @param null|Account $account
185
     */
186 17
    public function setCredit(?Account $account): void
187
    {
188 17
        if ($this->credit) {
189 1
            $this->credit->creditTransactionLineRemoved($this);
190
        }
191
192 17
        $this->credit = $account;
193
194 17
        if ($this->credit) {
195 17
            $this->credit->creditTransactionLineAdded($this);
196
        }
197 17
    }
198
199
    /**
200
     * Get credit account
201
     *
202
     * @return null|Account
203
     */
204 14
    public function getCredit(): ?Account
205
    {
206 14
        return $this->credit;
207
    }
208
209
    /**
210
     * Get related equipment or service
211
     *
212
     * @return null|Bookable
213
     */
214 4
    public function getBookable(): ?Bookable
215
    {
216 4
        return $this->bookable;
217
    }
218
219
    /**
220
     * Set related equipment or service
221
     *
222
     * @param null|Bookable $bookable
223
     */
224 6
    public function setBookable(?Bookable $bookable): void
225
    {
226 6
        $this->bookable = $bookable;
227 6
    }
228
229
    /**
230
     * Set balance
231
     *
232
     * @param Money $balance
233
     */
234 17
    public function setBalance(Money $balance): void
235
    {
236 17
        $this->balance = $balance;
237 17
    }
238
239
    /**
240
     * @return Money
241
     */
242 12
    public function getBalance(): Money
243
    {
244 12
        return $this->balance;
245
    }
246
247
    /**
248
     * Set date of transaction
249
     *
250
     * @param Chronos $transactionDate
251
     */
252 18
    public function setTransactionDate(Chronos $transactionDate): void
253
    {
254 18
        $this->transactionDate = $transactionDate;
255 18
    }
256
257
    /**
258
     * Get date of transaction
259
     *
260
     * @return Chronos
261
     */
262 2
    public function getTransactionDate(): Chronos
263
    {
264 2
        return $this->transactionDate;
265
    }
266
267
    /**
268
     * Set transaction tag
269
     *
270
     * @param null|TransactionTag $transactionTag
271
     */
272
    public function setTransactionTag(?TransactionTag $transactionTag): void
273
    {
274
        $this->transactionTag = $transactionTag;
275
    }
276
277
    /**
278
     * Get transaction tag
279
     *
280
     * @return null|TransactionTag
281
     */
282
    public function getTransactionTag(): ?TransactionTag
283
    {
284
        return $this->transactionTag;
285
    }
286
287
    /**
288
     * Whether this line of transaction was reconciled (e.g. from a bank statement)
289
     *
290
     * @return bool
291
     */
292
    public function isReconciled(): bool
293
    {
294
        return $this->isReconciled;
295
    }
296
297
    /**
298
     * Whether this line of transaction was reconciled (e.g. from a bank statement)
299
     *
300
     * @param bool $isReconciled
301
     */
302 3
    public function setIsReconciled(bool $isReconciled): void
303
    {
304 3
        $this->isReconciled = $isReconciled;
305 3
    }
306
}
307