src/Entity/ProjectClosure.php line 70

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use MedBrief\MSR\Controller\ProjectClosure\ProjectClosureOptions;
  8. use MedBrief\MSR\Dto\MatterClosureDto;
  9. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * @ApiResource(
  14. * collectionOperations={
  15. * "post"={"access_control"="is_granted('CREATE_PROJECT_CLOSURE', object.getProject())"},
  16. * "options"={
  17. * "method"="GET",
  18. * "path"="/project_closures/options",
  19. * "controller"=ProjectClosureOptions::class,
  20. * "defaults"={"_api_receive"=false}
  21. * },
  22. * "matter_closure_create"={
  23. * "access_control"="is_granted('CREATE_PROJECT_CLOSURE', object.getProject())",
  24. * "method"="POST",
  25. * "input"=MatterClosureDto::class,
  26. * "output"=MatterClosureDto::class,
  27. * "path"="/matter_closure/create",
  28. * "normalization_context"={"groups"={"matter_closure:read"}},
  29. * "denormalization_context"={"groups"={"matter_closure:create"}},
  30. * "validation_groups"={"matter_closure:create"},
  31. * "openapi_context"={
  32. * "summary"="Close a matter.",
  33. * "description"="Use this call to mark a matter for closure. See [Create Matter](/docs/api/detail#create-matter-closure)"
  34. * }
  35. * },
  36. * "matter_closure_cancel"={
  37. * "access_control"="is_granted('CANCEL_DELETE', object.getProject())",
  38. * "method"="POST",
  39. * "input"=MatterClosureDto::class,
  40. * "output"=MatterClosureDto::class,
  41. * "path"="/matter_closure/cancel",
  42. * "normalization_context"={"groups"={"matter_closure:cancel"}},
  43. * "denormalization_context"={"groups"={"matter_closure:cancel"}},
  44. * "validation_groups"={"matter_closure:cancel"},
  45. * "openapi_context"={
  46. * "summary"="Cancel matter closure (within cool of period).",
  47. * "description"="Use this call to cancel a matter marked for closure. See [Create Matter](/docs/api/detail#cancel-matter-closure)"
  48. * }
  49. * },
  50. * },
  51. * itemOperations={
  52. * "get"={
  53. * "access_control"="is_granted('READ', object)",
  54. * "normalization_context"={"groups"={"project_closure:read"}, "enable_max_depth"=true, "skip_null_values" = true}
  55. * },
  56. * }
  57. * )
  58. *
  59. * @ORM\Table(name="ProjectClosure")
  60. *
  61. * @ORM\Entity
  62. *
  63. * @Audit\Auditable
  64. *
  65. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  66. */
  67. class ProjectClosure
  68. {
  69. use FilterableClassConstantsTrait;
  70. public const CLOSURE_FINANCIAL_SETTLED_OPTION_YES = 'yes';
  71. public const CLOSURE_FINANCIAL_SETTLED_OPTION_YES__LABEL = 'Yes';
  72. public const CLOSURE_FINANCIAL_SETTLED_OPTION_NO = 'no';
  73. public const CLOSURE_FINANCIAL_SETTLED_OPTION_NO__LABEL = 'No';
  74. public const CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE = 'CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE';
  75. public const CLOSURE_FINANCIAL_SETTLED_REASON_EVIDENCE__LABEL = 'Decision to discontinue after exchange of expert evidence';
  76. public const CLOSURE_FINANCIAL_SETTLED_REASON_MEETING = 'CLOSURE_FINANCIAL_SETTLED_REASON_MEETING';
  77. public const CLOSURE_FINANCIAL_SETTLED_REASON_MEETING__LABEL = 'Decision to discontinue after Expert meetings';
  78. public const CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED = 'CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED';
  79. public const CLOSURE_FINANCIAL_SETTLED_REASON_DEFENDED__LABEL = 'Matter successfully defended';
  80. public const CLOSURE_FINANCIAL_SETTLED_REASON_OTHER = 'CLOSURE_FINANCIAL_SETTLED_REASON_OTHER';
  81. public const CLOSURE_FINANCIAL_SETTLED_REASON_OTHER__LABEL = 'Other';
  82. public const CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE = 'CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE';
  83. public const CLOSURE_MATTER_LITIGATED_NO_REASON_BEFORE__LABEL = 'Closed before expert evidence';
  84. public const CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER = 'CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER';
  85. public const CLOSURE_MATTER_LITIGATED_NO_REASON_AFTER__LABEL = 'Closed Following unsupportive expert evidence';
  86. public const CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED = 'CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED';
  87. public const CLOSURE_MATTER_LITIGATED_NO_REASON_ADMITTED__LABEL = 'Admitted/Settled';
  88. public const CLOSURE_TYPE_ARCHIVE = 'archive';
  89. public const CLOSURE_TYPE_DELETE = 'delete';
  90. /**
  91. * @var int
  92. *
  93. * @ORM\Column(name="id", type="integer")
  94. *
  95. * @ORM\Id
  96. *
  97. * @ORM\GeneratedValue(strategy="IDENTITY")
  98. */
  99. private $id;
  100. /**
  101. * @var \DateTime
  102. *
  103. * @ORM\Column(name="created", type="datetime")
  104. *
  105. * @Gedmo\Timestampable(on="create")
  106. */
  107. private $created;
  108. /**
  109. * @var \DateTime
  110. *
  111. * @ORM\Column(name="updated", type="datetime")
  112. *
  113. * @Gedmo\Timestampable(on="update")
  114. */
  115. private $updated;
  116. /**
  117. * @var \DateTime|null
  118. *
  119. * @ORM\Column(name="completedAt", type="datetime", nullable=true)
  120. */
  121. private $completedAt;
  122. /**
  123. * Whether the matter was litigated or not
  124. *
  125. * @var bool
  126. *
  127. * @Groups({"project_closure:read"})
  128. *
  129. * @Assert\Expression(
  130. * "this.getProject().getClosureQuestionsOptional() or value !== null",
  131. * message="This field is required"
  132. * )
  133. *
  134. * @ORM\Column(name="matterLitigated", type="boolean", nullable=true)
  135. */
  136. private $matterLitigated;
  137. /**
  138. * Option confirming if financial settlement was achieved
  139. *
  140. * @var string
  141. *
  142. * @Assert\Expression(
  143. * "this.getProject().getClosureQuestionsOptional() or value != '' or this.getMatterLitigated() === false",
  144. * message="This field is required"
  145. * )
  146. *
  147. * @ORM\Column(name="financialSettledAchieved", type="text", nullable=true)
  148. */
  149. private $financialSettledAchieved;
  150. /**
  151. * The settlement amount
  152. *
  153. * @var int
  154. *
  155. * @Assert\Expression(
  156. * "this.getProject().getClosureQuestionsOptional() or value != '' or this.getFinancialSettledAchieved() === 'no' or this.getFinancialSettledAchieved() === null or this.getFinancialSettledAchieved() === ''",
  157. * message="This field is required"
  158. * )
  159. *
  160. * @ORM\Column(name="financialSettledAchievedAmount", type="float", nullable=true)
  161. */
  162. private $financialSettledAchievedAmount;
  163. /**
  164. * The reason for not settled
  165. *
  166. * @var string
  167. *
  168. * @Assert\Expression(
  169. * "this.getProject().getClosureQuestionsOptional() or value != '' or this.getFinancialSettledAchieved() === 'yes' or this.getFinancialSettledAchieved() === null or this.getFinancialSettledAchieved() === ''",
  170. * message="This field is required"
  171. * )
  172. *
  173. * @ORM\Column(name="reasonForNotSettled", type="text", nullable=true)
  174. */
  175. private $reasonForNotSettled;
  176. /**
  177. * Explanation for reason not being settled.
  178. *
  179. * @var string
  180. *
  181. * @Assert\Expression(
  182. * "this.getProject().getClosureQuestionsOptional() or value != '' or this.getReasonForNotSettled() !== 'CLOSURE_FINANCIAL_SETTLED_REASON_OTHER' or this.getReasonForNotSettled() === ''",
  183. * message="This field is required"
  184. * )
  185. *
  186. * @ORM\Column(name="reasonForNotSettledOther", type="text", nullable=true)
  187. */
  188. private $reasonForNotSettledOther;
  189. /**
  190. * Explanation for reason not being settled.
  191. *
  192. * @var string|null
  193. *
  194. * @Assert\Expression(
  195. * "this.getProject().getClosureQuestionsOptional() or value != '' or this.getMatterLitigated() === true",
  196. * message="This field is required"
  197. * )
  198. *
  199. * @ORM\Column(name="reasonForNotSettledNo", type="text", nullable=true)
  200. */
  201. private $reasonForNotSettledNo;
  202. /**
  203. * @var string|null
  204. *
  205. * @ORM\Column(name="closureType", type="text", nullable=true)
  206. */
  207. private $closureType;
  208. /**
  209. * @var \DateTime|null
  210. *
  211. * @ORM\Column(name="scheduledDeletionDate", type="datetime", nullable=true)
  212. */
  213. private $scheduledDeletionDate;
  214. /**
  215. * @var Project
  216. *
  217. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="projectClosure")
  218. *
  219. * @ORM\JoinColumns({
  220. *
  221. * @ORM\JoinColumn(name="project_id", referencedColumnName="id", unique=true)
  222. * })
  223. */
  224. private $project;
  225. /**
  226. * @var User
  227. *
  228. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\User", inversedBy="projectClosures")
  229. *
  230. * @ORM\JoinColumns({
  231. *
  232. * @ORM\JoinColumn(name="closedBy_id", referencedColumnName="id")
  233. * })
  234. */
  235. private $closedBy;
  236. /**
  237. * Return id as a string
  238. *
  239. * @return string
  240. */
  241. public function __toString()
  242. {
  243. return (string) $this->getId();
  244. }
  245. /**
  246. * Get id
  247. *
  248. * @return int
  249. */
  250. public function getId()
  251. {
  252. return $this->id;
  253. }
  254. /**
  255. * Set completedAt
  256. *
  257. * @param \DateTime $completedAt
  258. *
  259. * @return ProjectClosure
  260. */
  261. public function setCompletedAt(?\DateTime $completedAt = null)
  262. {
  263. $this->completedAt = $completedAt;
  264. return $this;
  265. }
  266. /**
  267. * Get completedAt
  268. *
  269. * @return \DateTime
  270. */
  271. public function getCompletedAt()
  272. {
  273. return $this->completedAt;
  274. }
  275. /**
  276. * Set matterLitigated
  277. *
  278. * @param bool $matterLitigated
  279. *
  280. * @return ProjectClosure
  281. */
  282. public function setMatterLitigated(?bool $matterLitigated = null)
  283. {
  284. $this->matterLitigated = $matterLitigated;
  285. return $this;
  286. }
  287. /**
  288. * Get matterLitigated
  289. *
  290. * @return bool
  291. */
  292. public function getMatterLitigated()
  293. {
  294. return $this->matterLitigated;
  295. }
  296. /**
  297. * Set financialSettledAchieved
  298. *
  299. * @param string $financialSettledAchieved
  300. *
  301. * @return ProjectClosure
  302. */
  303. public function setFinancialSettledAchieved(?string $financialSettledAchieved = null)
  304. {
  305. $this->financialSettledAchieved = $financialSettledAchieved;
  306. return $this;
  307. }
  308. /**
  309. * Get financialSettledAchieved
  310. *
  311. * @return string
  312. */
  313. public function getFinancialSettledAchieved()
  314. {
  315. return $this->financialSettledAchieved;
  316. }
  317. /**
  318. * Set financialSettledAchievedAmount
  319. *
  320. * @param float $financialSettledAchievedAmount
  321. *
  322. * @return ProjectClosure
  323. */
  324. public function setFinancialSettledAchievedAmount(?float $financialSettledAchievedAmount = null)
  325. {
  326. $this->financialSettledAchievedAmount = $financialSettledAchievedAmount;
  327. return $this;
  328. }
  329. /**
  330. * Get financialSettledAchievedAmount
  331. *
  332. * @return float
  333. */
  334. public function getFinancialSettledAchievedAmount()
  335. {
  336. return $this->financialSettledAchievedAmount;
  337. }
  338. /**
  339. * Set reasonForNotSettled
  340. *
  341. * @param string $reasonForNotSettled
  342. *
  343. * @return ProjectClosure
  344. */
  345. public function setReasonForNotSettled(?string $reasonForNotSettled = null)
  346. {
  347. $this->reasonForNotSettled = $reasonForNotSettled;
  348. return $this;
  349. }
  350. /**
  351. * Get reasonForNotSettled
  352. *
  353. * @return string
  354. */
  355. public function getReasonForNotSettled()
  356. {
  357. return $this->reasonForNotSettled;
  358. }
  359. /**
  360. * Set reasonForNotSettledOther
  361. *
  362. * @param string $reasonForNotSettledOther
  363. *
  364. * @return ProjectClosure
  365. */
  366. public function setReasonForNotSettledOther(?string $reasonForNotSettledOther = null)
  367. {
  368. $this->reasonForNotSettledOther = $reasonForNotSettledOther;
  369. return $this;
  370. }
  371. /**
  372. * Get reasonForNotSettledOther
  373. *
  374. * @return string
  375. */
  376. public function getReasonForNotSettledOther()
  377. {
  378. return $this->reasonForNotSettledOther;
  379. }
  380. /**
  381. * Set reasonForNotSettledNo
  382. *
  383. * @param string $reasonForNotSettledNo
  384. *
  385. * @return ProjectClosure
  386. */
  387. public function setReasonForNotSettledNo(?string $reasonForNotSettledNo = null)
  388. {
  389. $this->reasonForNotSettledNo = $reasonForNotSettledNo;
  390. return $this;
  391. }
  392. /**
  393. * Get reasonForNotSettledNo
  394. *
  395. * @return string
  396. */
  397. public function getReasonForNotSettledNo()
  398. {
  399. return $this->reasonForNotSettledNo;
  400. }
  401. /**
  402. * Set created.
  403. *
  404. * @param \DateTime $created
  405. *
  406. * @return ProjectClosure
  407. */
  408. public function setCreated(\DateTime $created)
  409. {
  410. $this->created = $created;
  411. return $this;
  412. }
  413. /**
  414. * Get created.
  415. *
  416. * @return \DateTime
  417. */
  418. public function getCreated()
  419. {
  420. return $this->created;
  421. }
  422. /**
  423. * Set updated.
  424. *
  425. * @param \DateTime $updated
  426. *
  427. * @return ProjectClosure
  428. */
  429. public function setUpdated(\DateTime $updated)
  430. {
  431. $this->updated = $updated;
  432. return $this;
  433. }
  434. /**
  435. * Get updated.
  436. *
  437. * @return \DateTime
  438. */
  439. public function getUpdated()
  440. {
  441. return $this->updated;
  442. }
  443. /**
  444. * Set project.
  445. *
  446. * @param Project|null $project
  447. *
  448. * @return ProjectClosure
  449. */
  450. public function setProject(?Project $project = null)
  451. {
  452. $this->project = $project;
  453. return $this;
  454. }
  455. /**
  456. * Get project.
  457. *
  458. * @return Project|null
  459. */
  460. public function getProject()
  461. {
  462. return $this->project;
  463. }
  464. /**
  465. * Set closedBy.
  466. *
  467. * @param User|null $closedBy
  468. *
  469. * @return ProjectClosure
  470. */
  471. public function setClosedBy(?User $closedBy = null)
  472. {
  473. $this->closedBy = $closedBy;
  474. return $this;
  475. }
  476. /**
  477. * Get closedBy.
  478. *
  479. * @return User|null
  480. */
  481. public function getClosedBy()
  482. {
  483. return $this->closedBy;
  484. }
  485. /**
  486. * Get reasonForNotSettled as Label
  487. *
  488. * @return string
  489. */
  490. public function getReasonForNotSettledLabel()
  491. {
  492. $financialSettledReasons = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_REASON'));
  493. return $financialSettledReasons[$this->getReasonForNotSettled()] ?? '';
  494. }
  495. /**
  496. * Get reasonForNotSettledNo as Label
  497. *
  498. * @return string
  499. */
  500. public function getReasonForNotSettledNoLabel()
  501. {
  502. $matterLitigatedNoReasons = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_MATTER_LITIGATED_NO_REASON'));
  503. return $matterLitigatedNoReasons[$this->getReasonForNotSettledNo()] ?? '';
  504. }
  505. /**
  506. * @return array
  507. */
  508. public static function getFinancialSettledWithLabels(): array
  509. {
  510. return self::getConstantsWithLabels('CLOSURE_FINANCIAL_SETTLED_OPTION');
  511. }
  512. /**
  513. * @return array
  514. */
  515. public static function getFinancialSettledReasonsWithLabels(): array
  516. {
  517. return self::getConstantsWithLabels('CLOSURE_FINANCIAL_SETTLED_REASON');
  518. }
  519. /**
  520. * @return array
  521. */
  522. public static function getMatterLitigatedNoReasonsWithLabels(): array
  523. {
  524. return self::getConstantsWithLabels('CLOSURE_MATTER_LITIGATED_NO_REASON');
  525. }
  526. /**
  527. * @return array
  528. */
  529. public static function getAllClosureOptionsWithLabels(): array
  530. {
  531. return [
  532. 'financialSettledOptions' => self::getFinancialSettledWithLabels(),
  533. 'financialSettledReasons' => self::getFinancialSettledReasonsWithLabels(),
  534. 'matterLitigatedNoReasons' => self::getMatterLitigatedNoReasonsWithLabels(),
  535. ];
  536. }
  537. /**
  538. *
  539. * @return array
  540. */
  541. public static function getFinancialSettledOptionChoices()
  542. {
  543. return static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_OPTION');
  544. }
  545. /**
  546. * @return array
  547. */
  548. public static function getFinancialSettledReasonChoices()
  549. {
  550. return static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_REASON');
  551. }
  552. /**
  553. * @return array
  554. */
  555. public static function getMatterLitigatedNoReasonChoices()
  556. {
  557. return static::getConstantsWithLabelsAsChoices('CLOSURE_MATTER_LITIGATED_NO_REASON');
  558. }
  559. /**
  560. * Get financialSettledAchieved as Label
  561. *
  562. * @return string
  563. */
  564. public function getFinancialSettledAchievedLabel()
  565. {
  566. $financialSettledAchieved = array_flip(static::getConstantsWithLabelsAsChoices('CLOSURE_FINANCIAL_SETTLED_OPTION'));
  567. return $financialSettledAchieved[$this->getFinancialSettledAchieved()] ?? '';
  568. }
  569. /**
  570. * Get the value of closureType
  571. *
  572. * @return string
  573. */
  574. public function getClosureType()
  575. {
  576. return $this->closureType;
  577. }
  578. /**
  579. * Set the value of closureType
  580. *
  581. * @param string $closureType
  582. *
  583. * @return self
  584. */
  585. public function setClosureType(?string $closureType = null)
  586. {
  587. $this->closureType = $closureType;
  588. return $this;
  589. }
  590. /**
  591. * Return true if matter closureType is equal to archive
  592. *
  593. * @return bool
  594. */
  595. public function isArchive()
  596. {
  597. return $this->getClosureType() === $this::CLOSURE_TYPE_ARCHIVE;
  598. }
  599. /**
  600. * Return true if matter closureType is equal to delete
  601. *
  602. * @return bool
  603. */
  604. public function isDeletion()
  605. {
  606. return $this->getClosureType() === $this::CLOSURE_TYPE_DELETE;
  607. }
  608. /**
  609. * @return \DateTimeInterface|null
  610. */
  611. public function getScheduledDeletionDate(): ?\DateTimeInterface
  612. {
  613. return $this->scheduledDeletionDate;
  614. }
  615. /**
  616. * @param \DateTimeInterface|null $scheduledDeletionDate
  617. *
  618. * @return self
  619. */
  620. public function setScheduledDeletionDate(?\DateTimeInterface $scheduledDeletionDate): self
  621. {
  622. $this->scheduledDeletionDate = $scheduledDeletionDate;
  623. return $this;
  624. }
  625. }