90 lines
1.8 KiB
PHP
90 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Enum\TicketData;
|
|
use App\Repository\PaymentRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: PaymentRepository::class)]
|
|
class Payment
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $sessionId = null;
|
|
|
|
#[ORM\Column]
|
|
private ?bool $completed = null;
|
|
|
|
#[ORM\OneToOne(inversedBy: 'payment', cascade: ['persist', 'remove'], fetch: 'EAGER')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?Customer $customer = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?float $donation = null;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getSessionId(): ?string
|
|
{
|
|
return $this->sessionId;
|
|
}
|
|
|
|
public function setSessionId(string $sessionId): static
|
|
{
|
|
$this->sessionId = $sessionId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isCompleted(): ?bool
|
|
{
|
|
return $this->completed;
|
|
}
|
|
|
|
public function setCompleted(bool $completed): static
|
|
{
|
|
$this->completed = $completed;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCustomer(): ?Customer
|
|
{
|
|
return $this->customer;
|
|
}
|
|
|
|
public function setCustomer(Customer $customer): static
|
|
{
|
|
$this->customer = $customer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTotal(): float
|
|
{
|
|
return $this->customer->getTickets()->reduce(function (float $total, Ticket $ticket) {
|
|
return $total + TicketData::TICKET_DATA[$ticket->getType()]['price'];
|
|
}, 0);
|
|
}
|
|
|
|
public function getDonation(): ?float
|
|
{
|
|
return $this->donation;
|
|
}
|
|
|
|
public function setDonation(?float $donation): static
|
|
{
|
|
$this->donation = $donation;
|
|
|
|
return $this;
|
|
}
|
|
}
|