Failed Conditions
Push — master ( 2e19e9...f7c150 )
by Sam
08:00
created

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