EquipmentLoan.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?php
  2. namespace AppBundle\Entity\Product;
  3. use AppBundle\Annotation\ExportSplitFields;
  4. use AppBundle\Entity\AccessAndFunction\Access;
  5. use AppBundle\Entity\Core\Tagg;
  6. use AppBundle\Entity\Person\Person;
  7. use AppBundle\Entity\Traits\ActivityPeriodTrait;
  8. use AppBundle\Entity\Traits\BillingRuleTrait;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Dunglas\ApiBundle\Annotation\Iri;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use AppBundle\Entity\Traits\TimestampableEntity;
  15. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  16. use AppBundle\Validator\Constraints\Product as OpentalentAssert;
  17. /**
  18. * Location d'éaquipement,
  19. * Fait le lien entre un Access et un Equipment sur une période donnée
  20. *
  21. * @Iri("http://schema.org/EquipmentLoan")
  22. * @OpentalentAssert\EquipmentLoanAvailableRent
  23. */
  24. #[ORM\Entity]
  25. class EquipmentLoan
  26. {
  27. use TimestampableEntity;
  28. use CreatorUpdaterEntity;
  29. use ActivityPeriodTrait;
  30. use BillingRuleTrait;
  31. /**
  32. * @var int
  33. */
  34. #[ORM\Column(type: 'integer')]
  35. #[ORM\Id]
  36. #[ORM\GeneratedValue(strategy: 'AUTO')]
  37. #[Groups(['equipmentloan', 'equipmentrent_list', 'equipmentloan_list', 'accessequipment_grid', 'own_access', 'access_details', 'equipment_details', 'own_student_access', 'equipment_list', 'equipmentmediatheque_list', 'equipmentcostume_list', 'equipment_availability_form'])]
  38. private $id;
  39. /**
  40. * @var Access
  41. */
  42. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access', inversedBy: 'equipmentLoans', cascade: ['persist'])]
  43. #[ORM\JoinColumn(nullable: false)]
  44. #[Assert\NotNull]
  45. #[Groups(['equipmentloan', 'equipmentrent_list', 'equipmentloan_list', 'equipment_details_equipmentloanfiltered', 'equipment_list_equipmentloan', 'equipmentmediatheque_list_equipmentloan', 'equipmentcostume_list_equipmentloan', 'equipment_availability_form', 'equipmentloan_list', 'equipmentrent_list'])]
  46. private $borrower;
  47. /**
  48. * @var Equipment
  49. */
  50. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Product\Equipment', inversedBy: 'equipmentLoan')]
  51. #[Groups(['equipmentloan', 'equipmentrent_list', 'equipmentloan_list', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'access_details_equipmentloans', 'own_student_access_equipmentloans', 'equipment_availability_form'])]
  52. private $equipment;
  53. /**
  54. * @var \DateTime
  55. */
  56. #[ORM\Column(type: 'date', nullable: true)]
  57. #[Assert\Date]
  58. #[Groups(['equipmentloan', 'equipmentrent_list', 'equipmentloan_list', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'access_details_equipmentloans', 'own_student_access_equipmentloans', 'equipment_availability_form'])]
  59. private $endDateTheorical;
  60. /**
  61. * @var string
  62. */
  63. #[ORM\Column(type: 'string', nullable: true)]
  64. #[Assert\Type(type: 'string')]
  65. #[Assert\Choice(callback: ['\AppBundle\Enum\Product\LoanTypeEnum', 'toArray'])]
  66. #[Groups(['equipmentloan', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'access_details_equipmentloans', 'own_student_access_equipmentloans', 'equipmentloan_list', 'equipment_list_equipmentloan', 'equipmentmediatheque_list_equipmentloan', 'equipmentcostume_list_equipmentloan', 'equipment_availability_form'])]
  67. private $type;
  68. /**
  69. * @var float
  70. *
  71. *
  72. */
  73. #[ORM\Column(type: 'float', nullable: true)]
  74. #[Assert\Type(type: 'float')]
  75. #[Groups(['equipmentloan', 'equipmentrent_list', 'equipmentloan_list', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'own_student_access_equipmentloans', 'equipment_availability_form'])]
  76. private $deposit;
  77. /**
  78. * @var float
  79. */
  80. #[ORM\Column(type: 'float', nullable: true)]
  81. #[Assert\Type(type: 'float')]
  82. #[Groups(['equipmentloan', 'equipmentrent_list', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'own_student_access_equipmentloans', 'equipment_availability_form'])]
  83. private $amount;
  84. /**
  85. * @var bool
  86. */
  87. #[ORM\Column(type: 'boolean', nullable: true)]
  88. #[Assert\Type(type: 'boolean')]
  89. #[Groups(['equipmentloan', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans', 'own_student_access_equipmentloans', 'equipment_availability_form'])]
  90. private $forcingAmount = false;
  91. /**
  92. * @var ArrayCollection<BillLine>
  93. */
  94. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Billing\BillLine', mappedBy: 'equipmentLoan', orphanRemoval: true)]
  95. #[Groups(['equipmentloan_billline'])]
  96. private $billLines;
  97. /**
  98. * @var ArrayCollection<BillingIntangibleExcludeDate>
  99. */
  100. #[Assert\Valid]
  101. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Billing\BillingIntangibleExcludeDate', mappedBy: 'equipmentLoan', cascade: ['persist'], orphanRemoval: true)]
  102. #[Groups(['accessfictionalintangible', 'accessequipment_grid_equipmentloans', 'own_access_equipmentloans'])]
  103. private $billingIntangibleExcludeDates;
  104. /**
  105. * @var string
  106. * @ExportSplitFields({"borrower.person.name","borrower.person.givenName","type","startDate","endDate"})
  107. *
  108. */
  109. #[Groups(['template'])]
  110. private $fullLabelTemplate;
  111. /**
  112. * @var ArrayCollection<Tagg>
  113. */
  114. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'equipmentLoans')]
  115. #[Assert\Valid]
  116. #[ORM\JoinTable(name: 'tag_equipmentLoan', joinColumns: [], inverseJoinColumns: [])]
  117. #[ORM\JoinColumn(name: 'equipmentLoan_id', referencedColumnName: 'id')]
  118. #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  119. #[Groups(['equipmentloan_tags', 'manage_tags', 'equipmentloan_list', 'equipmentrent_list'])]
  120. private $tags;
  121. public function __construct()
  122. {
  123. $this->billLines = new ArrayCollection();
  124. $this->billingIntangibleExcludeDates = new ArrayCollection();
  125. $this->tags = new ArrayCollection();
  126. }
  127. /**
  128. * Sets id.
  129. *
  130. * @param int $id
  131. *
  132. * @return $this
  133. */
  134. public function setId($id)
  135. {
  136. $this->id = $id;
  137. return $this;
  138. }
  139. /**
  140. * Gets id.
  141. *
  142. * @return int
  143. */
  144. public function getId()
  145. {
  146. return $this->id;
  147. }
  148. /**
  149. * @param Access|null $borrower
  150. * @return $this
  151. */
  152. public function setBorrower(Access $borrower = null)
  153. {
  154. $this->borrower = $borrower;
  155. return $this;
  156. }
  157. /**
  158. * Gets Borrower.
  159. *
  160. * @return Access
  161. */
  162. public function getBorrower()
  163. {
  164. return $this->borrower;
  165. }
  166. /**
  167. * Sets equipment.
  168. *
  169. * @param Equipment $equipment
  170. *
  171. * @return $this
  172. */
  173. public function setEquipment(Equipment $equipment = null)
  174. {
  175. $this->equipment = $equipment;
  176. return $this;
  177. }
  178. /**
  179. * Gets equipment.
  180. *
  181. * @return Equipment
  182. */
  183. public function getEquipment()
  184. {
  185. return $this->equipment;
  186. }
  187. /**
  188. * Sets endDateTheorical.
  189. *
  190. * @param \DateTime $endDateTheorical
  191. *
  192. * @return $this
  193. */
  194. public function setEndDateTheorical(\DateTime $endDateTheorical = null)
  195. {
  196. $this->endDateTheorical = $endDateTheorical;
  197. return $this;
  198. }
  199. /**
  200. * Gets endDateTheorical.
  201. *
  202. * @return \DateTime
  203. */
  204. public function getEndDateTheorical()
  205. {
  206. return $this->endDateTheorical ? $this->endDateTheorical->format('Y-m-d') : $this->endDateTheorical;
  207. }
  208. /**
  209. * Sets type.
  210. *
  211. * @param string $type
  212. *
  213. * @return $this
  214. */
  215. public function setType($type)
  216. {
  217. $this->type = $type;
  218. return $this;
  219. }
  220. /**
  221. * Gets type.
  222. *
  223. * @return string
  224. */
  225. public function getType()
  226. {
  227. return $this->type;
  228. }
  229. /**
  230. * Sets deposit.
  231. *
  232. * @param float $deposit
  233. *
  234. * @return $this
  235. */
  236. public function setDeposit($deposit)
  237. {
  238. $this->deposit = floatval($deposit);
  239. return $this;
  240. }
  241. /**
  242. * Gets deposit.
  243. *
  244. * @return float
  245. */
  246. public function getDeposit()
  247. {
  248. return $this->deposit;
  249. }
  250. /**
  251. * Sets amount.
  252. *
  253. * @param float $amount
  254. *
  255. * @return $this
  256. */
  257. public function setAmount($amount)
  258. {
  259. $this->amount = floatval($amount);
  260. return $this;
  261. }
  262. /**
  263. * Gets amount.
  264. *
  265. * @return float
  266. */
  267. public function getAmount()
  268. {
  269. return $this->amount;
  270. }
  271. /**
  272. * Add billLine
  273. *
  274. * @param \AppBundle\Entity\Billing\BillLine $billLine
  275. *
  276. * @return EquipmentLoan
  277. */
  278. public function addBillLine(\AppBundle\Entity\Billing\BillLine $billLine)
  279. {
  280. $this->billLines[] = $billLine;
  281. return $this;
  282. }
  283. /**
  284. * Remove billLine
  285. *
  286. * @param \AppBundle\Entity\Billing\BillLine $billLine
  287. */
  288. public function removeBillLine(\AppBundle\Entity\Billing\BillLine $billLine)
  289. {
  290. $this->billLines->removeElement($billLine);
  291. }
  292. /**
  293. * Get billLines
  294. *
  295. * @return \Doctrine\Common\Collections\Collection
  296. */
  297. public function getBillLines()
  298. {
  299. return $this->billLines;
  300. }
  301. /**
  302. * Add billingIntangibleExcludeDate
  303. *
  304. * @param \AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate
  305. *
  306. * @return EquipmentLoan
  307. */
  308. public function addBillingIntangibleExcludeDate(\AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate)
  309. {
  310. $this->billingIntangibleExcludeDates[] = $billingIntangibleExcludeDate;
  311. return $this;
  312. }
  313. /**
  314. * Remove billingIntangibleExcludeDate
  315. *
  316. * @param \AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate
  317. */
  318. public function removeBillingIntangibleExcludeDate(\AppBundle\Entity\Billing\BillingIntangibleExcludeDate $billingIntangibleExcludeDate)
  319. {
  320. $this->billingIntangibleExcludeDates->removeElement($billingIntangibleExcludeDate);
  321. }
  322. /**
  323. * Get billingIntangibleExcludeDates
  324. *
  325. * @return \Doctrine\Common\Collections\Collection
  326. */
  327. public function getBillingIntangibleExcludeDates()
  328. {
  329. return $this->billingIntangibleExcludeDates;
  330. }
  331. /**
  332. * Set forcingAmount
  333. *
  334. * @param boolean $forcingAmount
  335. *
  336. * @return EquipmentLoan
  337. */
  338. public function setForcingAmount($forcingAmount)
  339. {
  340. $this->forcingAmount = $forcingAmount;
  341. return $this;
  342. }
  343. /**
  344. * Get forcingAmount
  345. *
  346. * @return boolean
  347. */
  348. public function getForcingAmount()
  349. {
  350. return $this->forcingAmount;
  351. }
  352. /**
  353. * Gets full label.
  354. *
  355. * @return array
  356. */
  357. public function getFullLabelTemplate()
  358. {
  359. $fullLabel = [];
  360. $fullLabel[] = $this->getBorrower() ? $this->getBorrower()->getPerson()->getFullNameTemplate() : '';
  361. $fullLabel[] = ['value' => $this->getType(), 'translate' => true];
  362. $fullLabel[] = ['type' => 'date', 'value' => $this->getStartDate()];
  363. if(!empty($this->getEndDate()))
  364. $fullLabel[] = ['type' => 'date', 'value' => $this->getEndDate()];
  365. return $fullLabel;
  366. }
  367. /**
  368. * Add tag
  369. *
  370. * @param \AppBundle\Entity\Core\Tagg $tag
  371. *
  372. * @return EquipmentLoan
  373. */
  374. public function addTag(\AppBundle\Entity\Core\Tagg $tag)
  375. {
  376. $this->tags[] = $tag;
  377. return $this;
  378. }
  379. /**
  380. * Remove tag
  381. *
  382. * @param \AppBundle\Entity\Core\Tagg $tag
  383. */
  384. public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
  385. {
  386. $this->tags->removeElement($tag);
  387. }
  388. /**
  389. * Get tags
  390. *
  391. * @return \Doctrine\Common\Collections\Collection
  392. */
  393. public function getTags()
  394. {
  395. return $this->tags;
  396. }
  397. }