Transaction::setTransactionDate()   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 1
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\Enum\ExpenseClaimStatus;
8
use Application\Repository\TransactionRepository;
9
use Application\Traits\HasAutomaticUnsignedBalance;
10
use Application\Traits\HasRemarks;
11
use Cake\Chronos\Chronos;
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\HasInternalRemarks;
16
use Ecodev\Felix\Model\Traits\HasName;
17
use Money\Money;
18
19
/**
20
 * An accounting journal entry (simple or compound).
21
 */
22
#[ORM\Entity(TransactionRepository::class)]
23
class Transaction extends AbstractModel
24
{
25
    use HasAutomaticUnsignedBalance;
26
    use HasInternalRemarks;
27
    use HasName;
28
    use HasRemarks;
29
30
    #[ORM\Column(type: 'datetime')]
31
    private Chronos $transactionDate;
32
33
    /**
34
     * @var Collection<int, TransactionLine>
35
     */
36
    #[ORM\OneToMany(targetEntity: TransactionLine::class, mappedBy: 'transaction')]
37
    private Collection $transactionLines;
38
39
    /**
40
     * @var Collection<int, AccountingDocument>
41
     */
42
    #[ORM\OneToMany(targetEntity: AccountingDocument::class, mappedBy: 'transaction')]
43
    private Collection $accountingDocuments;
44
45
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
46
    #[ORM\ManyToOne(targetEntity: ExpenseClaim::class, inversedBy: 'transactions')]
47
    private ?ExpenseClaim $expenseClaim = null;
48
49
    #[ORM\Column(type: 'string', length: 18, options: ['default' => ''])]
50
    private string $datatransRef = '';
51
52 41
    public function __construct()
53
    {
54 41
        $this->balance = Money::CHF(0);
55 41
        $this->transactionLines = new ArrayCollection();
56 41
        $this->accountingDocuments = new ArrayCollection();
57
    }
58
59
    /**
60
     * Set date of transaction.
61
     */
62 33
    public function setTransactionDate(Chronos $transactionDate): void
63
    {
64 33
        $this->transactionDate = $transactionDate;
65
    }
66
67
    /**
68
     * Get date of transaction.
69
     */
70 18
    public function getTransactionDate(): Chronos
71
    {
72 18
        return $this->transactionDate;
73
    }
74
75
    /**
76
     * Notify when a transaction line is added
77
     * This should only be called by TransactionLine::setTransaction().
78
     */
79 32
    public function transactionLineAdded(TransactionLine $transactionLine): void
80
    {
81 32
        $this->transactionLines->add($transactionLine);
82
    }
83
84
    /**
85
     * Notify when a transaction line is removed
86
     * This should only be called by TransactionLine::setTransaction().
87
     */
88 1
    public function transactionLineRemoved(TransactionLine $transactionLine): void
89
    {
90 1
        $this->transactionLines->removeElement($transactionLine);
91
    }
92
93 29
    public function getTransactionLines(): Collection
94
    {
95 29
        return $this->transactionLines;
96
    }
97
98
    /**
99
     * Notify the transaction that an accounting document was added
100
     * This should only be called by AccountingDocument::setTransaction().
101
     */
102 1
    public function accountingDocumentAdded(AccountingDocument $document): void
103
    {
104 1
        $this->accountingDocuments->add($document);
105
    }
106
107
    /**
108
     * Notify the transaction that an accounting document was removed
109
     * This should only be called by AccountingDocument::setTransaction().
110
     */
111 1
    public function accountingDocumentRemoved(AccountingDocument $document): void
112
    {
113 1
        $this->accountingDocuments->removeElement($document);
114
    }
115
116
    /**
117
     * Get accounting documents.
118
     */
119 1
    public function getAccountingDocuments(): Collection
120
    {
121 1
        return $this->accountingDocuments;
122
    }
123
124
    /**
125
     * Set expense claim.
126
     */
127 1
    public function setExpenseClaim(?ExpenseClaim $expenseClaim): void
128
    {
129 1
        if ($this->expenseClaim) {
130 1
            $this->expenseClaim->transactionRemoved($this);
131
        }
132
133 1
        $this->expenseClaim = $expenseClaim;
134
135 1
        if ($this->expenseClaim) {
136 1
            $this->expenseClaim->transactionAdded($this);
137 1
            $this->expenseClaim->setStatus(ExpenseClaimStatus::Processed);
138
        }
139
    }
140
141
    /**
142
     * Get expense claim.
143
     */
144
    public function getExpenseClaim(): ?ExpenseClaim
145
    {
146
        return $this->expenseClaim;
147
    }
148
149
    /**
150
     * Get Datatrans payment reference number.
151
     */
152 5
    public function setDatatransRef(string $datatransRef): void
153
    {
154 5
        $this->datatransRef = $datatransRef;
155
    }
156
157
    /**
158
     * Set Datatrans payment reference number.
159
     */
160 9
    public function getDatatransRef(): string
161
    {
162 9
        return $this->datatransRef;
163
    }
164
}
165