Failed Conditions
Push — master ( a427b2...509ea4 )
by Adrien
16:44
created

TransactionLine   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 229
Duplicated Lines 0 %

Test Coverage

Coverage 95.74%

Importance

Changes 0
Metric Value
wmc 23
eloc 41
dl 0
loc 229
ccs 45
cts 47
cp 0.9574
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getBalance() 0 3 1
A setCredit() 0 10 3
A getImportedId() 0 3 1
A getBookable() 0 3 1
A getTransactionTag() 0 3 1
A setIsReconciled() 0 3 1
A setImportedId() 0 3 1
A setBookable() 0 3 1
A getCredit() 0 3 1
A setDebit() 0 10 3
A getDebit() 0 3 1
A setTransactionTag() 0 3 1
A getTransaction() 0 3 1
A setBalance() 0 3 1
A setTransactionDate() 0 3 1
A isReconciled() 0 3 1
A setTransaction() 0 8 2
A getTransactionDate() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasRemarks;
8
use Cake\Chronos\Chronos;
9
use Doctrine\ORM\Mapping as ORM;
10
use Ecodev\Felix\Model\Traits\HasName;
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
 * @ORM\Table(uniqueConstraints={
19
 *     @ORM\UniqueConstraint(name="unique_import", columns={"transaction_date", "imported_id"})
20
 * })
21
 * @API\Filters({
22
 *     @API\Filter(field="custom", operator="Application\Api\Input\Operator\TransactionWithDocumentOperatorType", type="boolean"),
23
 *     @API\Filter(field="custom", operator="Application\Api\Input\Operator\TransactionExportOperatorType", type="boolean"),
24
 *     @API\Filter(field="custom", operator="Application\Api\Input\Operator\CreditOrDebitAccountOperatorType", type="id"),
25
 * })
26
 */
27
class TransactionLine extends AbstractModel
28
{
29
    use HasName;
30
    use HasRemarks;
31
32
    /**
33
     * @ORM\ManyToOne(targetEntity="Transaction", inversedBy="transactionLines")
34
     * @ORM\JoinColumns({
35
     *     @ORM\JoinColumn(nullable=false, onDelete="RESTRICT")
36
     * })
37
     */
38
    private ?Transaction $transaction = null;
39
40
    /**
41
     * @ORM\ManyToOne(targetEntity="Account", inversedBy="debitTransactionLines")
42
     * @ORM\JoinColumns({
43
     *     @ORM\JoinColumn(nullable=true, onDelete="RESTRICT")
44
     * })
45
     */
46
    private ?\Application\Model\Account $debit = null;
47
48
    /**
49
     * @ORM\ManyToOne(targetEntity="Account", inversedBy="creditTransactionLines")
50
     * @ORM\JoinColumns({
51
     *     @ORM\JoinColumn(nullable=true, onDelete="RESTRICT")
52
     * })
53
     */
54
    private ?\Application\Model\Account $credit = null;
55
56
    /**
57
     * @ORM\ManyToOne(targetEntity="Bookable")
58
     * @ORM\JoinColumns({
59
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
60
     * })
61
     */
62
    private ?\Application\Model\Bookable $bookable = null;
63
64
    /**
65
     * @ORM\Column(type="Money", options={"unsigned" = true})
66
     */
67
    private \Money\Money $balance;
68
69
    /**
70
     * @ORM\Column(type="datetime")
71
     */
72
    private \Cake\Chronos\Chronos $transactionDate;
73
74
    /**
75
     * @ORM\ManyToOne(targetEntity="TransactionTag")
76
     * @ORM\JoinColumns({
77
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
78
     * })
79
     */
80
    private ?\Application\Model\TransactionTag $transactionTag = null;
81
82
    /**
83
     * @ORM\Column(type="boolean", options={"default" = 0})
84
     */
85
    private bool $isReconciled = false;
86
87
    /**
88
     * This store the value of CAMT 054 `<EndToEndId>`, or else `<AcctSvcrRef>`, element that should
89
     * hopefully be a universally unique transaction identifier.
90
     *
91
     * An absence of value means the line was not imported.
92
     *
93
     * @ORM\Column(type="string", length=35, nullable=true)
94
     */
95
    private ?string $importedId = null;
96
97
    /**
98
     * Set importedId.
99
     *
100
     * @API\Exclude
101
     */
102 8
    public function setImportedId(string $importedId): void
103
    {
104 8
        $this->importedId = $importedId;
105
    }
106
107
    /**
108
     * Get importedId.
109
     */
110 7
    public function getImportedId(): ?string
111
    {
112 7
        return $this->importedId;
113
    }
114
115
    /**
116
     * @API\Exclude
117
     */
118 29
    public function setTransaction(Transaction $transaction): void
119
    {
120 29
        if ($this->transaction) {
121 1
            $this->transaction->transactionLineRemoved($this);
122
        }
123
124 29
        $this->transaction = $transaction;
125 29
        $transaction->transactionLineAdded($this);
126
    }
127
128 6
    public function getTransaction(): Transaction
129
    {
130 6
        return $this->transaction;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->transaction could return the type null which is incompatible with the type-hinted return Application\Model\Transaction. Consider adding an additional type-check to rule them out.
Loading history...
131
    }
132
133
    /**
134
     * Set debit account.
135
     */
136 29
    public function setDebit(?Account $account): void
137
    {
138 29
        if ($this->debit) {
139 1
            $this->debit->debitTransactionLineRemoved($this);
140
        }
141
142 29
        $this->debit = $account;
143
144 29
        if ($this->debit) {
145 29
            $this->debit->debitTransactionLineAdded($this);
146
        }
147
    }
148
149
    /**
150
     * Get debit account.
151
     */
152 21
    public function getDebit(): ?Account
153
    {
154 21
        return $this->debit;
155
    }
156
157
    /**
158
     * Set credit account.
159
     */
160 29
    public function setCredit(?Account $account): void
161
    {
162 29
        if ($this->credit) {
163 1
            $this->credit->creditTransactionLineRemoved($this);
164
        }
165
166 29
        $this->credit = $account;
167
168 29
        if ($this->credit) {
169 29
            $this->credit->creditTransactionLineAdded($this);
170
        }
171
    }
172
173
    /**
174
     * Get credit account.
175
     */
176 21
    public function getCredit(): ?Account
177
    {
178 21
        return $this->credit;
179
    }
180
181
    /**
182
     * Get related equipment or service.
183
     */
184 5
    public function getBookable(): ?Bookable
185
    {
186 5
        return $this->bookable;
187
    }
188
189
    /**
190
     * Set related equipment or service.
191
     */
192 12
    public function setBookable(?Bookable $bookable): void
193
    {
194 12
        $this->bookable = $bookable;
195
    }
196
197
    /**
198
     * Set balance.
199
     */
200 29
    public function setBalance(Money $balance): void
201
    {
202 29
        $this->balance = $balance;
203
    }
204
205 19
    public function getBalance(): Money
206
    {
207 19
        return $this->balance;
208
    }
209
210
    /**
211
     * Set date of transaction.
212
     */
213 30
    public function setTransactionDate(Chronos $transactionDate): void
214
    {
215 30
        $this->transactionDate = $transactionDate;
216
    }
217
218
    /**
219
     * Get date of transaction.
220
     */
221 8
    public function getTransactionDate(): Chronos
222
    {
223 8
        return $this->transactionDate;
224
    }
225
226
    /**
227
     * Set transaction tag.
228
     */
229
    public function setTransactionTag(?TransactionTag $transactionTag): void
230
    {
231
        $this->transactionTag = $transactionTag;
232
    }
233
234
    /**
235
     * Get transaction tag.
236
     */
237 1
    public function getTransactionTag(): ?TransactionTag
238
    {
239 1
        return $this->transactionTag;
240
    }
241
242
    /**
243
     * Whether this line of transaction was reconciled (e.g. from a bank statement).
244
     */
245 2
    public function isReconciled(): bool
246
    {
247 2
        return $this->isReconciled;
248
    }
249
250
    /**
251
     * Whether this line of transaction was reconciled (e.g. from a bank statement).
252
     */
253 4
    public function setIsReconciled(bool $isReconciled): void
254
    {
255 4
        $this->isReconciled = $isReconciled;
256
    }
257
}
258