<?php
namespace MedBrief\MSR\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use MedBrief\MSR\Controller\ProjectClosure\ProjectClosureOptions;
use MedBrief\MSR\Dto\MatterClosureDto;
use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* collectionOperations={
* "post"={"access_control"="is_granted('CREATE_PROJECT_CLOSURE', object.getProject())"},
* "options"={
* "method"="GET",
* "path"="/project_closures/options",
* "controller"=ProjectClosureOptions::class,
* "defaults"={"_api_receive"=false}
* },
* "matter_closure_create"={
* "access_control"="is_granted('CREATE_PROJECT_CLOSURE', object.getProject())",
* "method"="POST",
* "input"=MatterClosureDto::class,
* "output"=MatterClosureDto::class,
* "path"="/matter_closure/create",
* "normalization_context"={"groups"={"matter_closure:read"}},
* "denormalization_context"={"groups"={"matter_closure:create"}},
* "validation_groups"={"matter_closure:create"},
* "openapi_context"={
* "summary"="Close a matter.",
* "description"="Use this call to mark a matter for closure. See [Create Matter](/docs/api/detail#create-matter-closure)"
* }
* },
* "matter_closure_cancel"={
* "access_control"="is_granted('CANCEL_DELETE', object.getProject())",
* "method"="POST",
* "input"=MatterClosureDto::class,
* "output"=MatterClosureDto::class,
* "path"="/matter_closure/cancel",
* "normalization_context"={"groups"={"matter_closure:cancel"}},
* "denormalization_context"={"groups"={"matter_closure:cancel"}},
* "validation_groups"={"matter_closure:cancel"},
* "openapi_context"={
* "summary"="Cancel matter closure (within cool of period).",
* "description"="Use this call to cancel a matter marked for closure. See [Create Matter](/docs/api/detail#cancel-matter-closure)"
* }
* },
* },
* itemOperations={
* "get"={
* "access_control"="is_granted('READ', object)",
* "normalization_context"={"groups"={"project_closure:read"}, "enable_max_depth"=true, "skip_null_values" = true}
* },
* }
* )
*
* @ORM\Table(name="ProjectClosure")
*
* @ORM\Entity
*
* @Audit\Auditable
*
* @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
*/
class ProjectClosure
{
use FilterableClassConstantsTrait;
public const CLOSURE_FINANCIAL_SETTLED_OPTION_YES = 'yes';
public const CLOSURE_FINANCIAL_SETTLED_OPTION_YES__LABEL = 'Yes';
public const CLOSURE_FINANCIAL_SETTLED_OPTION_NO = 'no';
public const CLOSURE_FINANCIAL_SETTLED_OPTION_NO__LABEL = 'No';
public const CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE = 'CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE';
public const CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE__LABEL = 'Decision to discontinue after exchange of expert evidence';
public const CLOSURE_FINANCIAL_SETTLED_REASON_MEETING = 'CLOSURE_FINANCIAL_SETTLED_REASON_MEETING';
public const CLOSURE_FINANCIAL_SETTLED_REASON_MEETING__LABEL = 'Decision to discontinue after Expert meetings';
public const CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED = 'CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED';
public const CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED__LABEL = 'Matter successfully defended';
public const CLOSURE_FINANCIAL_SETTLED_REASON_OTHER = 'CLOSURE_FINANCIAL_SETTLED_REASON_OTHER';
public const CLOSURE_FINANCIAL_SETTLED_REASON_OTHER__LABEL = 'Other';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE = 'CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE__LABEL = 'Closed before expert evidence';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER = 'CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER__LABEL = 'Closed Following unsupportive expert evidence';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED = 'CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED';
public const CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED__LABEL = 'Admitted/Settled';
public const CLOSURE_TYPE_ARCHIVE = 'archive';
public const CLOSURE_TYPE_DELETE = 'delete';
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime")
*
* @Gedmo\Timestampable(on="create")
*/
private $created;
/**
* @var \DateTime
*
* @ORM\Column(name="updated", type="datetime")
*
* @Gedmo\Timestampable(on="update")
*/
private $updated;
/**
* @var \DateTime|null
*
* @ORM\Column(name="completedAt", type="datetime", nullable=true)
*/
private $completedAt;
/**
* Whether the matter was litigated or not
*
* @var bool
*
* @Groups({"project_closure:read"})
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value !== null",
* message="This field is required"
* )
*
* @ORM\Column(name="matterLitigated", type="boolean", nullable=true)
*/
private $matterLitigated;
/**
* Option confirming if financial settlement was achieved
*
* @var string
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value != '' or this.getMatterLitigated() === false",
* message="This field is required"
* )
*
* @ORM\Column(name="financialSettledAchieved", type="text", nullable=true)
*/
private $financialSettledAchieved;
/**
* The settlement amount
*
* @var int
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value != '' or this.getFinancialSettledAchieved() === 'no' or this.getFinancialSettledAchieved() === null or this.getFinancialSettledAchieved() === ''",
* message="This field is required"
* )
*
* @ORM\Column(name="financialSettledAchievedAmount", type="float", nullable=true)
*/
private $financialSettledAchievedAmount;
/**
* The reason for not settled
*
* @var string
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value != '' or this.getFinancialSettledAchieved() === 'yes' or this.getFinancialSettledAchieved() === null or this.getFinancialSettledAchieved() === ''",
* message="This field is required"
* )
*
* @ORM\Column(name="reasonForNotSettled", type="text", nullable=true)
*/
private $reasonForNotSettled;
/**
* Explanation for reason not being settled.
*
* @var string
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value != '' or this.getReasonForNotSettled() !== 'CLOSURE_FINANCIAL_SETTLED_REASON_OTHER' or this.getReasonForNotSettled() === ''",
* message="This field is required"
* )
*
* @ORM\Column(name="reasonForNotSettledOther", type="text", nullable=true)
*/
private $reasonForNotSettledOther;
/**
* Explanation for reason not being settled.
*
* @var string|null
*
* @Assert\Expression(
* "this.getProject().getClosureQuestionsOptional() or value != '' or this.getMatterLitigated() === true",
* message="This field is required"
* )
*
* @ORM\Column(name="reasonForNotSettledNo", type="text", nullable=true)
*/
private $reasonForNotSettledNo;
/**
* @var string|null
*
* @ORM\Column(name="closureType", type="text", nullable=true)
*/
private $closureType;
/**
* @var \DateTime|null
*
* @ORM\Column(name="scheduledDeletionDate", type="datetime", nullable=true)
*/
private $scheduledDeletionDate;
/**
* @var Project
*
* @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="projectClosure")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="project_id", referencedColumnName="id", unique=true)
* })
*/
private $project;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="projectClosures")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="closedBy_id", referencedColumnName="id")
* })
*/
private $closedBy;
/**
* Return id as a string
*
* @return string
*/
public function __toString()
{
return (string) $this->getId();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set completedAt
*
* @param \DateTime $completedAt
*
* @return ProjectClosure
*/
public function setCompletedAt(?\DateTime $completedAt = null)
{
$this->completedAt = $completedAt;
return $this;
}
/**
* Get completedAt
*
* @return \DateTime
*/
public function getCompletedAt()
{
return $this->completedAt;
}
/**
* Set matterLitigated
*
* @param bool $matterLitigated
*
* @return ProjectClosure
*/
public function setMatterLitigated(?bool $matterLitigated = null)
{
$this->matterLitigated = $matterLitigated;
return $this;
}
/**
* Get matterLitigated
*
* @return bool
*/
public function getMatterLitigated()
{
return $this->matterLitigated;
}
/**
* Set financialSettledAchieved
*
* @param string $financialSettledAchieved
*
* @return ProjectClosure
*/
public function setFinancialSettledAchieved(?string $financialSettledAchieved = null)
{
$this->financialSettledAchieved = $financialSettledAchieved;
return $this;
}
/**
* Get financialSettledAchieved
*
* @return string
*/
public function getFinancialSettledAchieved()
{
return $this->financialSettledAchieved;
}
/**
* Set financialSettledAchievedAmount
*
* @param float $financialSettledAchievedAmount
*
* @return ProjectClosure
*/
public function setFinancialSettledAchievedAmount(?float $financialSettledAchievedAmount = null)
{
$this->financialSettledAchievedAmount = $financialSettledAchievedAmount;
return $this;
}
/**
* Get financialSettledAchievedAmount
*
* @return float
*/
public function getFinancialSettledAchievedAmount()
{
return $this->financialSettledAchievedAmount;
}
/**
* Set reasonForNotSettled
*
* @param string $reasonForNotSettled
*
* @return ProjectClosure
*/
public function setReasonForNotSettled(?string $reasonForNotSettled = null)
{
$this->reasonForNotSettled = $reasonForNotSettled;
return $this;
}
/**
* Get reasonForNotSettled
*
* @return string
*/
public function getReasonForNotSettled()
{
return $this->reasonForNotSettled;
}
/**
* Set reasonForNotSettledOther
*
* @param string $reasonForNotSettledOther
*
* @return ProjectClosure
*/
public function setReasonForNotSettledOther(?string $reasonForNotSettledOther = null)
{
$this->reasonForNotSettledOther = $reasonForNotSettledOther;
return $this;
}
/**
* Get reasonForNotSettledOther
*
* @return string
*/
public function getReasonForNotSettledOther()
{
return $this->reasonForNotSettledOther;
}
/**
* Set reasonForNotSettledNo
*
* @param string $reasonForNotSettledNo
*
* @return ProjectClosure
*/
public function setReasonForNotSettledNo(?string $reasonForNotSettledNo = null)
{
$this->reasonForNotSettledNo = $reasonForNotSettledNo;
return $this;
}
/**
* Get reasonForNotSettledNo
*
* @return string
*/
public function getReasonForNotSettledNo()
{
return $this->reasonForNotSettledNo;
}
/**
* Set created.
*
* @param \DateTime $created
*
* @return ProjectClosure
*/
public function setCreated(\DateTime $created)
{
$this->created = $created;
return $this;
}
/**
* Get created.
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated.
*
* @param \DateTime $updated
*
* @return ProjectClosure
*/
public function setUpdated(\DateTime $updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated.
*
* @return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Set project.
*
* @param Project|null $project
*
* @return ProjectClosure
*/
public function setProject(?Project $project = null)
{
$this->project = $project;
return $this;
}
/**
* Get project.
*
* @return Project|null
*/
public function getProject()
{
return $this->project;
}
/**
* Set closedBy.
*
* @param User|null $closedBy
*
* @return ProjectClosure
*/
public function setClosedBy(?User $closedBy = null)
{
$this->closedBy = $closedBy;
return $this;
}
/**
* Get closedBy.
*
* @return User|null
*/
public function getClosedBy()
{
return $this->closedBy;
}
/**
* Get reasonForNotSettled as Label
*
* @return string
*/
public function getReasonForNotSettledLabel()
{
$financialSettledReasons = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_REASON'));
return $financialSettledReasons[$this->getReasonForNotSettled()] ?? '';
}
/**
* Get reasonForNotSettledNo as Label
*
* @return string
*/
public function getReasonForNotSettledNoLabel()
{
$matterLitigatedNoReasons = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_MATTER_LITIGATED_NO_REASON'));
return $matterLitigatedNoReasons[$this->getReasonForNotSettledNo()] ?? '';
}
/**
* @return array
*/
public static function getFinancialSettledWithLabels(): array
{
return self::getConstantsWithLabels('CLOSURE_FINANCIAL_SETTLED_OPTION');
}
/**
* @return array
*/
public static function getFinancialSettledReasonsWithLabels(): array
{
return self::getConstantsWithLabels('CLOSURE_FINANCIAL_SETTLED_REASON');
}
/**
* @return array
*/
public static function getMatterLitigatedNoReasonsWithLabels(): array
{
return self::getConstantsWithLabels('CLOSURE_MATTER_LITIGATED_NO_REASON');
}
/**
* @return array
*/
public static function getAllClosureOptionsWithLabels(): array
{
return [
'financialSettledOptions' => self::getFinancialSettledWithLabels(),
'financialSettledReasons' => self::getFinancialSettledReasonsWithLabels(),
'matterLitigatedNoReasons' => self::getMatterLitigatedNoReasonsWithLabels(),
];
}
/**
*
* @return array
*/
public static function getFinancialSettledOptionChoices()
{
return static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_OPTION');
}
/**
* @return array
*/
public static function getFinancialSettledReasonChoices()
{
return static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_REASON');
}
/**
* @return array
*/
public static function getMatterLitigatedNoReasonChoices()
{
return static::getConstantsWithLabelsAsChoices('CLOSURE_MATTER_LITIGATED_NO_REASON');
}
/**
* Get financialSettledAchieved as Label
*
* @return string
*/
public function getFinancialSettledAchievedLabel()
{
$financialSettledAchieved = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_OPTION'));
return $financialSettledAchieved[$this->getFinancialSettledAchieved()] ?? '';
}
/**
* Get the value of closureType
*
* @return string
*/
public function getClosureType()
{
return $this->closureType;
}
/**
* Set the value of closureType
*
* @param string $closureType
*
* @return self
*/
public function setClosureType(?string $closureType = null)
{
$this->closureType = $closureType;
return $this;
}
/**
* Return true if matter closureType is equal to archive
*
* @return bool
*/
public function isArchive()
{
return $this->getClosureType() === $this::CLOSURE_TYPE_ARCHIVE;
}
/**
* Return true if matter closureType is equal to delete
*
* @return bool
*/
public function isDeletion()
{
return $this->getClosureType() === $this::CLOSURE_TYPE_DELETE;
}
/**
* @return \DateTimeInterface|null
*/
public function getScheduledDeletionDate(): ?\DateTimeInterface
{
return $this->scheduledDeletionDate;
}
/**
* @param \DateTimeInterface|null $scheduledDeletionDate
*
* @return self
*/
public function setScheduledDeletionDate(?\DateTimeInterface $scheduledDeletionDate): self
{
$this->scheduledDeletionDate = $scheduledDeletionDate;
return $this;
}
}