Files
sprawozdania/project/src/Entity/Reports.php
T
2024-10-15 12:15:57 +02:00

216 lines
4.9 KiB
PHP

<?php
namespace App\Entity;
use App\Enum\ReportStatus;
use App\Enum\ReportTodoEnum;
use App\Helper\MonthHelper;
use App\Repository\ReportsRepository;
use App\Services\AddReports;
use App\Services\MailtoServices;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ReportsRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'report_cache')]
class Reports
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(referencedColumnName: "id", nullable: false)]
private ?Clients $client = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $dateStart = null;
/**
* @var Collection<int, ReportsTodo>
*/
#[ORM\OneToMany(targetEntity: ReportsTodo::class, mappedBy: 'report', orphanRemoval: true)]
#[ORM\Cache(usage: 'READ_ONLY', region: 'report_cache')]
private Collection $reportsTodos;
#[ORM\Column(options: ["default" => "0"])]
private bool $isDelete = false;
private int $numberOfReport = 0;
#[ORM\Column(options: ["default" => "0"])]
private bool $isDone = false;
#[ORM\Column]
private ?int $number = null;
public function __construct()
{
$this->reportsTodos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDateStart(): ?\DateTimeInterface
{
return $this->dateStart;
}
public function setDateStart(\DateTimeInterface $dateStart): static
{
$this->dateStart = $dateStart;
return $this;
}
public function getClient(): ?Clients
{
return $this->client;
}
public function setClient(?Clients $client): static
{
$this->client = $client;
return $this;
}
/**
* @return Collection<int, ReportsTodo>
*/
public function getReportsTodos(): Collection
{
return $this->reportsTodos;
}
public function addReportsTodo(ReportsTodo $reportsTodo): static
{
if (!$this->reportsTodos->contains($reportsTodo)) {
$this->reportsTodos->add($reportsTodo);
$reportsTodo->setReport($this);
}
return $this;
}
public function removeReportsTodo(ReportsTodo $reportsTodo): static
{
if ($this->reportsTodos->removeElement($reportsTodo)) {
// set the owning side to null (unless already changed)
if ($reportsTodo->getReport() === $this) {
$reportsTodo->setReport(null);
}
}
return $this;
}
public function isReportsTodo(ReportTodoEnum $enum): bool
{
$return = false;
foreach ($this->getReportsTodos() as $reportsTodo) {
if ($reportsTodo->getName() === $enum) {
$return = !$reportsTodo->isDeleted();
}
}
return $return;
}
public function isDone(): bool
{
return $this->isReportsTodo(ReportTodoEnum::COMPLETE);
}
public function isEmailSend(): bool
{
return $this->isReportsTodo(ReportTodoEnum::SENT_EMAIL);
}
public function countTodoReports(): int
{
$count = 0;
foreach ($this->getReportsTodos() as $reportsTodo) {
if (!$reportsTodo->isDeleted()) {
$count++;
}
}
return $count;
}
public function takeStatusTodo(): ReportStatus
{
if ($this->countTodoReports() === 0) {
return ReportStatus::INSERT;
}
$status = ReportStatus::WORKING;
foreach ($this->getReportsTodos() as $reportsTodo) {
if ($reportsTodo->isDeleted()) {
continue;
}
if ($reportsTodo->getName() === ReportTodoEnum::COMPLETE) {
$status = ReportStatus::COMPLETE;
break;
}
}
return $status;
}
public function isDelete(): ?bool
{
return $this->isDelete;
}
public function setDelete(bool $isDelete): static
{
$this->isDelete = $isDelete;
return $this;
}
public function getNumberOfReport(): int
{
return $this->numberOfReport;
}
public function setNumberOfReport(int $numberOfReport): void
{
$this->numberOfReport = $numberOfReport;
}
public function setDone(bool $isDone): static
{
$this->isDone = $isDone;
return $this;
}
public function getNumber(): ?int
{
return $this->number;
}
public function setNumber(int $number): static
{
$this->number = $number;
return $this;
}
public function takeMailToUrl(): string
{
$service = new MailtoServices();
return $service->takeUrl($this);
}
}