199 lines
4.4 KiB
PHP
199 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Core\Entity\EntityInterface;
|
|
use App\Repository\ExpenseReportRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: ExpenseReportRepository::class)]
|
|
class ExpenseReport implements EntityInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
protected $id;
|
|
|
|
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'expenseReports')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
protected $user;
|
|
|
|
#[ORM\Column(type: 'array')]
|
|
protected $moves = [];
|
|
|
|
#[ORM\Column(type: 'array')]
|
|
protected $variousPayments = [];
|
|
|
|
#[ORM\Column(type: 'datetime', nullable: true)]
|
|
protected $paidAt;
|
|
|
|
#[ORM\Column(type: 'array')]
|
|
protected $bills = [];
|
|
|
|
#[ORM\Column(type: 'date')]
|
|
protected $dateFrom;
|
|
|
|
#[ORM\Column(type: 'date')]
|
|
protected $dateTo;
|
|
|
|
#[ORM\Column(type: 'float')]
|
|
protected $scalePerKilometer;
|
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
|
|
protected $isRequestedPayment = false;
|
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
|
|
protected $isPaid = false;
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUser(): ?User
|
|
{
|
|
return $this->user;
|
|
}
|
|
|
|
public function setUser(?User $user): self
|
|
{
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMoves(): ?array
|
|
{
|
|
return $this->moves;
|
|
}
|
|
|
|
public function setMoves(array $moves): self
|
|
{
|
|
$this->moves = $moves;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getVariousPayments(): ?array
|
|
{
|
|
return $this->variousPayments;
|
|
}
|
|
|
|
public function setVariousPayments(array $variousPayments): self
|
|
{
|
|
$this->variousPayments = $variousPayments;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIsPaid(): ?bool
|
|
{
|
|
return $this->isPaid;
|
|
}
|
|
|
|
public function setIsPaid(bool $isPaid): self
|
|
{
|
|
$this->isPaid = $isPaid;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPaidAt(): ?\DateTimeInterface
|
|
{
|
|
return $this->paidAt;
|
|
}
|
|
|
|
public function setPaidAt(?\DateTimeInterface $paidAt): self
|
|
{
|
|
$this->paidAt = $paidAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getBills(): ?array
|
|
{
|
|
return $this->bills;
|
|
}
|
|
|
|
public function setBills(array $bills): self
|
|
{
|
|
$this->bills = $bills;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateFrom(): ?\DateTimeInterface
|
|
{
|
|
return $this->dateFrom;
|
|
}
|
|
|
|
public function setDateFrom(\DateTimeInterface $dateFrom): self
|
|
{
|
|
$this->dateFrom = $dateFrom;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDateTo(): ?\DateTimeInterface
|
|
{
|
|
return $this->dateTo;
|
|
}
|
|
|
|
public function setDateTo(\DateTimeInterface $dateTo): self
|
|
{
|
|
$this->dateTo = $dateTo;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getScalePerKilometer(): ?float
|
|
{
|
|
return $this->scalePerKilometer;
|
|
}
|
|
|
|
public function setScalePerKilometer(float $scalePerKilometer): self
|
|
{
|
|
$this->scalePerKilometer = $scalePerKilometer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getIsRequestedPayment(): ?bool
|
|
{
|
|
return $this->isRequestedPayment;
|
|
}
|
|
|
|
public function setIsRequestedPayment(bool $isRequestedPayment): self
|
|
{
|
|
$this->isRequestedPayment = $isRequestedPayment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTotalAmount(?string $of = null, array $data = []): float
|
|
{
|
|
$amount = 0;
|
|
|
|
if ('moves' === $of) {
|
|
foreach ($this->getMoves() as $data) {
|
|
$amount += $this->getTotalAmount('move', $data);
|
|
}
|
|
} elseif ('various_payments' === $of) {
|
|
foreach ($this->getVariousPayments() as $data) {
|
|
$amount += $this->getTotalAmount('various_payment', $data);
|
|
}
|
|
} elseif ('move' === $of) {
|
|
$amount += $data['highwayPay'];
|
|
$amount += $data['parkingPay'];
|
|
$amount += ($data['isRoundTrip'] ? 2 : 1) * $data['distance'] * $this->getScalePerKilometer();
|
|
} elseif ('various_payment' === $of) {
|
|
$amount += $data['amount'];
|
|
} else {
|
|
$amount += $this->getTotalAmount('moves');
|
|
$amount += $this->getTotalAmount('various_payments');
|
|
}
|
|
|
|
return $amount;
|
|
}
|
|
}
|