Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
48 / 48
100.00% covered (success)
100.00%
25 / 25
CRAP
100.00% covered (success)
100.00%
1 / 1
Transaction
100.00% covered (success)
100.00%
48 / 48
100.00% covered (success)
100.00%
25 / 25
26
100.00% covered (success)
100.00%
1 / 1
 getDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDate
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAmount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAmount
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDocument
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDocument
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDepId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDepId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRecipeNo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRecipeNo
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUser
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setType
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMethod
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMethod
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getStore
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStore
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDeposit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDeposit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setComment
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Entity;
6
7use App\Repository\TransactionRepository;
8use App\Type\TransactionType;
9use DateTime;
10use Doctrine\DBAL\Types\Types;
11use Doctrine\ORM\Mapping\Column;
12use Doctrine\ORM\Mapping\Entity;
13use Doctrine\ORM\Mapping\GeneratedValue;
14use Doctrine\ORM\Mapping\Id;
15use Doctrine\ORM\Mapping\JoinColumn;
16use Doctrine\ORM\Mapping\ManyToOne;
17use Doctrine\ORM\Mapping\OneToOne;
18use JsonSerializable;
19use Override;
20
21#[Entity(repositoryClass: TransactionRepository::class)]
22class Transaction implements JsonSerializable
23{
24    #[Column, Id, GeneratedValue]
25    protected ?int $id = null;
26
27    #[ManyToOne(targetEntity: Store::class)]
28    #[JoinColumn(name: 'store_id', referencedColumnName: 'id', nullable: false)]
29    protected Store $store;
30
31    #[ManyToOne(targetEntity: User::class)]
32    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false)]
33    protected User $user;
34
35    #[Column(enumType: TransactionType::class)]
36    private TransactionType $type;
37
38    /**
39     * The method
40     * Bar, bank, etc.
41     */
42    #[ManyToOne(targetEntity: PaymentMethod::class)]
43    #[JoinColumn(name: 'method_id', referencedColumnName: 'id', nullable: false)]
44    private PaymentMethod $method;
45
46    #[Column(type: Types::DATE_MUTABLE, nullable: false)]
47    private DateTime $date;
48
49    #[Column(type: Types::DECIMAL, precision: 13, scale: 2, nullable: false)]
50    private string $amount = '0';
51
52    #[Column(type: Types::INTEGER, length: 20, nullable: true)]
53    private int $document;
54
55    /**
56     * @deprecated
57     */
58    #[Column(type: Types::INTEGER, nullable: true)]
59    private ?int $depId = null;
60
61    #[OneToOne(targetEntity: Deposit::class, inversedBy: 'transaction', cascade: [
62        'persist',
63        'remove',
64    ])]
65    private ?Deposit $deposit = null;
66
67    #[Column(type: Types::INTEGER, nullable: true)]
68    private int $recipeNo = 0;
69
70    #[Column(length: 255, nullable: true)]
71    private ?string $comment = null;
72
73    public function getDate(): DateTime
74    {
75        return $this->date;
76    }
77
78    public function setDate(DateTime $date): self
79    {
80        $this->date = $date;
81
82        return $this;
83    }
84
85    public function getAmount(): string
86    {
87        return $this->amount;
88    }
89
90    public function setAmount(string $amount): self
91    {
92        $this->amount = $amount;
93
94        return $this;
95    }
96
97    public function getDocument(): int
98    {
99        return $this->document;
100    }
101
102    public function setDocument(int $document): self
103    {
104        $this->document = $document;
105
106        return $this;
107    }
108
109    public function getDepId(): ?int
110    {
111        return $this->depId;
112    }
113
114    public function setDepId(int $depId): self
115    {
116        $this->depId = $depId;
117
118        return $this;
119    }
120
121    public function getRecipeNo(): int
122    {
123        return $this->recipeNo;
124    }
125
126    public function setRecipeNo(int $recipeNo): self
127    {
128        $this->recipeNo = $recipeNo;
129
130        return $this;
131    }
132
133    public function getUser(): User
134    {
135        return $this->user;
136    }
137
138    public function setUser(User $user): static
139    {
140        $this->user = $user;
141
142        return $this;
143    }
144
145    public function getType(): TransactionType
146    {
147        return $this->type;
148    }
149
150    public function setType(TransactionType $type): static
151    {
152        $this->type = $type;
153
154        return $this;
155    }
156
157    public function getMethod(): PaymentMethod
158    {
159        return $this->method;
160    }
161
162    public function setMethod(PaymentMethod $paymentMethod): static
163    {
164        $this->method = $paymentMethod;
165
166        return $this;
167    }
168
169    public function getStore(): Store
170    {
171        return $this->store;
172    }
173
174    public function setStore(Store $store): static
175    {
176        $this->store = $store;
177
178        return $this;
179    }
180
181    public function getDeposit(): ?Deposit
182    {
183        return $this->deposit;
184    }
185
186    public function setDeposit(?Deposit $deposit): self
187    {
188        $this->deposit = $deposit;
189
190        return $this;
191    }
192
193    /**
194     * @return array{id: int|null, store: int|null, user: int|null, type: string, method: int|null, date: string, amount: string, document: int, depId: int|null, recipeNo: int}
195     */
196    #[Override]
197    public function jsonSerialize(): array
198    {
199        return [
200            'id' => $this->id,
201            'store' => $this->store->getId(),
202            'user' => $this->user->getId(),
203            'type' => $this->type->name,
204            'method' => $this->method->getId() ?: null,
205            'date' => $this->date->format('Y-m-d'),
206            'amount' => $this->amount,
207            'document' => $this->document,
208            'depId' => $this->depId,
209            'recipeNo' => $this->recipeNo,
210        ];
211    }
212
213    public function getId(): ?int
214    {
215        return $this->id;
216    }
217
218    public function setId(int $id): static
219    {
220        $this->id = $id;
221
222        return $this;
223    }
224
225    public function getComment(): ?string
226    {
227        return $this->comment;
228    }
229
230    public function setComment(?string $comment): self
231    {
232        $this->comment = $comment;
233
234        return $this;
235    }
236}