Files
myep-team/src/Entity/Disposition.php
T
2025-08-21 14:20:43 +02:00

281 lines
6.8 KiB
PHP

<?php
namespace App\Entity;
use App\Entity\Traits\BlameableEntity;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\DispositionRepository;
use Carbon\CarbonPeriod;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: DispositionRepository::class)]
class Disposition implements BlameableEntityInterface, TimestampableEntityInterface
{
use BlameableEntity;
use TimestampableEntity;
public const STATUS_NEW = 'new';
public const STATUS_CHECKING_CONTRACT = 'checking_contract';
public const STATUS_CONFIRMED = 'confirmed';
public const STATUS_ENDED = 'ended';
public const STATUS_CHECKING_INVOICE = 'checking_invoice';
public const STATUS_PAID = 'paid';
public const STATUS_COMPLETED = 'completed';
public const STATUS_CALLED_OFF = 'called_off';
public const CALLED_OFF_BY_TEAMER = 'teamer';
public const CALLED_OFF_BY_OFFICE = 'office';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column(length: 64)]
private ?string $status;
#[ORM\ManyToOne(inversedBy: 'dispositions')]
private ?Assignment $assignment;
#[ORM\ManyToOne(inversedBy: 'dispositions')]
private ?Teamer $teamer;
#[ORM\Column(nullable: true)]
private ?int $pickup;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $remarks;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $specialAgreements;
#[ORM\OneToMany(mappedBy: 'disposition', targetEntity: Upload::class, cascade: ['persist', 'remove'])]
private Collection $documents;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?Feedback $feedback = null;
#[ORM\Column(length: 64, nullable: true)]
private ?string $calledOffBy = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $calledOffReason = null;
public function __construct(Application $application)
{
$this->uuid = Uuid::v4();
$this->status = static::STATUS_NEW;
$this->assignment = $application->getAssignment();
$this->teamer = $application->getTeamer();
$this->pickup = $application->getPickup();
$this->specialAgreements = $application->getRequests();
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function getAssignment(): ?Assignment
{
return $this->assignment;
}
public function setAssignment(?Assignment $assignment): static
{
$this->assignment = $assignment;
return $this;
}
public function getTeamer(): ?Teamer
{
return $this->teamer;
}
public function setTeamer(?Teamer $teamer): static
{
$this->teamer = $teamer;
return $this;
}
public function getPickup(): ?int
{
return $this->pickup;
}
public function setPickup(?int $pickup): static
{
$this->pickup = $pickup;
return $this;
}
public function getRemarks(): ?string
{
return $this->remarks;
}
public function setRemarks(?string $remarks): static
{
$this->remarks = $remarks;
return $this;
}
public function getSpecialAgreements(): ?string
{
return $this->specialAgreements;
}
public function setSpecialAgreements(?string $specialAgreements): static
{
$this->specialAgreements = $specialAgreements;
return $this;
}
/**
* @return Collection<int, Upload>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function getDocumentByType(string $type): ?Upload
{
foreach ($this->getDocuments() as $upload) {
if ($type === $upload->getType()) {
return $upload;
}
}
return null;
}
public function addDocument(Upload $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setDisposition($this);
}
return $this;
}
public function removeDocument(Upload $document): static
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getDisposition() === $this) {
$document->setDisposition(null);
}
}
return $this;
}
public function getFeedback(): ?Feedback
{
return $this->feedback;
}
public function setFeedback(?Feedback $feedback): static
{
$this->feedback = $feedback;
return $this;
}
public function isContractDue(): bool
{
if (null !== $this->getDocumentByType(Upload::TYPE_CONTRACT)) {
return false;
}
$assignment = $this->getAssignment();
$assignmentPeriod = $assignment->getEffectivePeriod();
$dueDateFrom = $this->getCreatedAt()->modify('+7 days');
$dueDateTo = $assignmentPeriod->end->modify('-1 day');
$period = CarbonPeriod::create($dueDateFrom, $dueDateTo);
return $period->isStarted();
}
public function isContractRejected(): bool
{
if (null === $contractDocument = $this->getDocumentByType(Upload::TYPE_CONTRACT)) {
return false;
}
return $contractDocument->isRejected();
}
public function isInvoiceDue(): bool
{
if (null !== $this->getDocumentByType(Upload::TYPE_INVOICE)) {
return false;
}
$assignment = $this->getAssignment();
$assignmentPeriod = $assignment->getEffectivePeriod();
$period = CarbonPeriod::create($assignmentPeriod->getEndDate(), $assignmentPeriod->getEndDate()->modify('+14 days'));
return $period->isStarted();
}
public function getCalledOffBy(): ?string
{
return $this->calledOffBy;
}
public function setCalledOffBy(?string $calledOffBy): static
{
$this->calledOffBy = $calledOffBy;
return $this;
}
public function getCalledOffReason(): ?string
{
return $this->calledOffReason;
}
public function setCalledOffReason(?string $calledOffReason): static
{
$this->calledOffReason = $calledOffReason;
return $this;
}
}