Failed Conditions
Push — master ( 5fbadf...673c47 )
by Adrien
07:14
created

Transaction::getAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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\Traits\HasName;
8
use Application\Traits\HasRemarks;
9
use Cake\Chronos\Date;
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\Mapping as ORM;
13
14
/**
15
 * An accounting journal entry (simple or compound)
16
 *
17
 * @ORM\Entity(repositoryClass="Application\Repository\TransactionRepository")
18
 */
19
class Transaction extends AbstractModel
20
{
21
    use HasName;
22
    use HasRemarks;
23
24
    /**
25
     * @var Date
26
     * @ORM\Column(name="transactionDate", type="date")
27
     */
28
    private $transactionDate;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(type="text", length=65535)
34
     */
35
    private $internalRemarks = '';
36
37
    /**
38
     * @var Collection
39
     * @ORM\OneToMany(targetEntity="TransactionLine", mappedBy="transaction")
40
     */
41
    private $transactionLines;
42
43
    /**
44
     * @var Collection
45
     * @ORM\OneToMany(targetEntity="AccountingDocument", mappedBy="transaction")
46
     */
47
    private $accountingDocuments;
48
49
    /**
50
     * @var ExpenseClaim
51
     *
52
     * @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="transactions")
53
     * @ORM\JoinColumns({
54
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
55
     * })
56
     */
57
    private $expenseClaim;
58
59
    /**
60
     * Constructor
61
     */
62 7
    public function __construct()
63
    {
64 7
        $this->transactionLines = new ArrayCollection();
65 7
        $this->accountingDocuments = new ArrayCollection();
66 7
    }
67
68
    /**
69
     * Set date of transaction
70
     *
71
     * @param Date $transactionDate
72
     */
73 3
    public function setTransactionDate(Date $transactionDate): void
74
    {
75 3
        $this->transactionDate = $transactionDate;
76 3
    }
77
78
    /**
79
     * Get date of transaction
80
     *
81
     * @return Date
82
     */
83
    public function getTransactionDate(): Date
84
    {
85
        return $this->transactionDate;
86
    }
87
88
    /**
89
     * Set remarks for internal use
90
     *
91
     * @param string $internalRemarks
92
     */
93 2
    public function setInternalRemarks(string $internalRemarks): void
94
    {
95 2
        $this->internalRemarks = $internalRemarks;
96 2
    }
97
98
    /**
99
     * Get remarks for internal use
100
     *
101
     * @return string
102
     */
103
    public function getInternalRemarks(): string
104
    {
105
        return $this->internalRemarks;
106
    }
107
108
    /**
109
     * Notify when a transaction line is added
110
     * This should only be called by TransactionLine::setTransaction()
111
     *
112
     * @param TransactionLine $transactionLine
113
     */
114 2
    public function transactionLineAdded(TransactionLine $transactionLine): void
115
    {
116 2
        $this->transactionLines->add($transactionLine);
117 2
    }
118
119
    /**
120
     * Notify when a transaction line is removed
121
     * This should only be called by TransactionLine::setTransaction()
122
     *
123
     * @param TransactionLine $transactionLine
124
     */
125
    public function transactionLineRemoved(TransactionLine $transactionLine): void
126
    {
127
        $this->transactionLines->removeElement($transactionLine);
128
    }
129
130
    /**
131
     * @return Collection
132
     */
133 1
    public function getTransactionLines(): Collection
134
    {
135 1
        return $this->transactionLines;
136
    }
137
138
    /**
139
     * Notify the transaction that an accounting document was added
140
     * This should only be called by AccountingDocument::setTransaction()
141
     *
142
     * @param AccountingDocument $document
143
     */
144
    public function accountingDocumentAdded(AccountingDocument $document): void
145
    {
146
        $this->accountingDocuments->add($document);
147
    }
148
149
    /**
150
     * Notify the transaction that an accounting document was removed
151
     * This should only be called by AccountingDocument::setTransaction()
152
     *
153
     * @param AccountingDocument $document
154
     */
155
    public function accountingDocumentRemoved(AccountingDocument $document): void
156
    {
157
        $this->accountingDocuments->removeElement($document);
158
    }
159
160
    /**
161
     * Get accounting documents
162
     *
163
     * @return Collection
164
     */
165
    public function getAccountingDocuments(): Collection
166
    {
167
        return $this->accountingDocuments;
168
    }
169
170
    /**
171
     * Set expense claim
172
     *
173
     * @param null|ExpenseClaim $expenseClaim
174
     */
175 1
    public function setExpenseClaim(?ExpenseClaim $expenseClaim): void
176
    {
177 1
        if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) {
178 1
            $this->expenseClaim->transactionRemoved($this);
179
        }
180
181 1
        $this->expenseClaim = $expenseClaim;
182 1
        $this->expenseClaim && $this->expenseClaim->transactionAdded($this);
183 1
    }
184
185
    /**
186
     * Get expense claim
187
     *
188
     * @return null|ExpenseClaim
189
     */
190
    public function getExpenseClaim(): ?ExpenseClaim
191
    {
192
        return $this->expenseClaim;
193
    }
194
}
195