AbstractBillingIntangible.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. namespace AppBundle\Entity\Billing;
  3. use AppBundle\Entity\Core\Tagg;
  4. use AppBundle\Entity\Organization\Organization;
  5. use AppBundle\Entity\Product\Intangible;
  6. use AppBundle\Entity\Traits\ActivityPeriodTrait;
  7. use AppBundle\Entity\Traits\BillingRuleTrait;
  8. use AppBundle\Entity\Traits\LockableTrait;
  9. use AppBundle\Enum\Billing\PeriodicityTypeEnum;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Dunglas\ApiBundle\Annotation\Iri;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use AppBundle\Annotation\DefaultField;
  16. use AppBundle\Entity\Traits\TimestampableEntity;
  17. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  18. /**
  19. * Enregistrement d'un produit à facturer par une Organization, un Access ou un EducationalProject
  20. * Classe de base de @see AccessIntangible, EducationalProjectIntangible
  21. *
  22. *
  23. */
  24. #[ORM\Entity]
  25. #[ORM\Table(name: 'BillingIntangible')]
  26. #[ORM\InheritanceType('SINGLE_TABLE')]
  27. #[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
  28. #[ORM\DiscriminatorMap(['access' => 'AccessIntangible', 'educationalproject' => 'EducationalProjectIntangible'])]
  29. abstract class AbstractBillingIntangible
  30. {
  31. use TimestampableEntity;
  32. use CreatorUpdaterEntity;
  33. use ActivityPeriodTrait;
  34. use BillingRuleTrait;
  35. /**
  36. * @var int
  37. */
  38. #[ORM\Column(type: 'integer')]
  39. #[ORM\Id]
  40. #[ORM\GeneratedValue(strategy: 'AUTO')]
  41. #[Groups(['accessintangible', 'educationalprojectintangible', 'access_details', 'student_registration', 'educationalproject_details', 'accessbilling_edit'])]
  42. private $id;
  43. /**
  44. * @var Intangible
  45. */
  46. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Product\Intangible', inversedBy: 'accessIntangibles')]
  47. #[ORM\JoinColumn(nullable: false)]
  48. #[Assert\NotNull]
  49. #[Groups(['accessintangible', 'accessintangible_intangible', 'educationalprojectintangible', 'access_details_accessintangibles', 'student_registration_accessintangibles', 'educationalproject_details_educationalprojectintangibles', 'accessbilling_edit_accessintangibles', 'access_intangible_list'])]
  50. private $intangible;
  51. /**
  52. * @var string
  53. *
  54. * @Iri("https://schema.org/description")
  55. */
  56. #[ORM\Column(type: 'text', nullable: true)]
  57. #[Assert\Type(type: 'string')]
  58. #[Groups(['accessintangible', 'educationalprojectintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles', 'access_intangible_list'])]
  59. private $customDescription;
  60. /**
  61. * @var int
  62. */
  63. #[ORM\Column(type: 'integer', nullable: true)]
  64. #[Assert\Type(type: 'integer', message: 'invalid-integer')]
  65. #[Groups(['accessintangible', 'educationalprojectintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles'])]
  66. private $quantity;
  67. /**
  68. * @var float
  69. */
  70. #[ORM\Column(type: 'float', nullable: true)]
  71. #[Assert\Type(type: 'float')]
  72. #[Groups(['accessintangible', 'educationalprojectintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles'])]
  73. private $forcedAmount;
  74. /**
  75. * @var bool
  76. */
  77. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  78. #[Assert\Type(type: 'boolean')]
  79. #[Assert\NotNull]
  80. #[Groups(['accessintangible', 'educationalprojectintangible', 'student_registration_accessintangibles', 'accessbilling_edit_accessintangibles'])]
  81. private $isForcedAmount = false;
  82. /**
  83. * @var ArrayCollection<Tagg>
  84. */
  85. #[ORM\ManyToMany(targetEntity: 'AppBundle\Entity\Core\Tagg', cascade: ['persist'], inversedBy: 'billingIntangibles')]
  86. #[Assert\Valid]
  87. #[ORM\JoinTable(name: 'tag_billingIntangible', joinColumns: [], inverseJoinColumns: [])]
  88. #[ORM\JoinColumn(name: 'billingIntangible_id', referencedColumnName: 'id')]
  89. #[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id')]
  90. #[Groups(['billingintangible_tags', 'manage_tags', 'access_intangible_list'])]
  91. private $tags;
  92. /**
  93. * The constructor
  94. */
  95. public function __construct() {
  96. $this->tags= new ArrayCollection();
  97. }
  98. /**
  99. * Sets id.
  100. *
  101. * @param int $id
  102. *
  103. * @return $this
  104. */
  105. public function setId($id)
  106. {
  107. $this->id = $id;
  108. return $this;
  109. }
  110. /**
  111. * Gets id.
  112. *
  113. * @return int
  114. */
  115. public function getId()
  116. {
  117. return $this->id;
  118. }
  119. /**
  120. * Set customDescription
  121. *
  122. * @param string $customDescription
  123. *
  124. * @return AbstractBillingIntangible
  125. */
  126. public function setCustomDescription($customDescription)
  127. {
  128. $this->customDescription = $customDescription;
  129. return $this;
  130. }
  131. /**
  132. * Get customDescription
  133. *
  134. * @return string
  135. */
  136. public function getCustomDescription()
  137. {
  138. return $this->customDescription;
  139. }
  140. /**
  141. * Set quantity
  142. *
  143. * @param integer $quantity
  144. *
  145. * @return AbstractBillingIntangible
  146. */
  147. public function setQuantity($quantity)
  148. {
  149. $this->quantity = $quantity;
  150. return $this;
  151. }
  152. /**
  153. * Get quantity
  154. *
  155. * @return integer
  156. */
  157. public function getQuantity()
  158. {
  159. return $this->quantity;
  160. }
  161. /**
  162. * Set forcedAmount
  163. *
  164. * @param float $forcedAmount
  165. *
  166. * @return AbstractBillingIntangible
  167. */
  168. public function setForcedAmount($forcedAmount)
  169. {
  170. $this->forcedAmount = floatval($forcedAmount);
  171. return $this;
  172. }
  173. /**
  174. * Get forcedAmount
  175. *
  176. * @return float
  177. */
  178. public function getForcedAmount()
  179. {
  180. return $this->forcedAmount;
  181. }
  182. /**
  183. * Set isForcedAmount
  184. *
  185. * @param boolean $isForcedAmount
  186. *
  187. * @return AbstractBillingIntangible
  188. */
  189. public function setIsForcedAmount($isForcedAmount)
  190. {
  191. $this->isForcedAmount = $isForcedAmount;
  192. return $this;
  193. }
  194. /**
  195. * Get isForcedAmount
  196. *
  197. * @return boolean
  198. */
  199. public function getIsForcedAmount()
  200. {
  201. return $this->isForcedAmount;
  202. }
  203. /**
  204. * Set intangible
  205. *
  206. * @param \AppBundle\Entity\Product\Intangible $intangible
  207. *
  208. * @return AbstractBillingIntangible
  209. */
  210. public function setIntangible(\AppBundle\Entity\Product\Intangible $intangible)
  211. {
  212. $this->intangible = $intangible;
  213. return $this;
  214. }
  215. /**
  216. * Get intangible
  217. *
  218. * @return \AppBundle\Entity\Product\Intangible
  219. */
  220. public function getIntangible()
  221. {
  222. return $this->intangible;
  223. }
  224. /**
  225. * Add tag
  226. *
  227. * @param \AppBundle\Entity\Core\Tagg $tag
  228. *
  229. * @return AbstractBillingIntangible
  230. */
  231. public function addTag(\AppBundle\Entity\Core\Tagg $tag)
  232. {
  233. $this->tags[] = $tag;
  234. return $this;
  235. }
  236. /**
  237. * Remove tag
  238. *
  239. * @param \AppBundle\Entity\Core\Tagg $tag
  240. */
  241. public function removeTag(\AppBundle\Entity\Core\Tagg $tag)
  242. {
  243. $this->tags->removeElement($tag);
  244. }
  245. /**
  246. * Get tags
  247. *
  248. * @return \Doctrine\Common\Collections\Collection
  249. */
  250. public function getTags()
  251. {
  252. return $this->tags;
  253. }
  254. /**
  255. * Sets start date
  256. *
  257. * @param \DateTime $startDate
  258. * @return $this
  259. */
  260. public function setStartDate(\DateTime $startDate = null) {
  261. if($startDate == null) $startDate = new \DateTime();
  262. $this->startDate = $startDate;
  263. if(!empty($this->getIntangible()) && $this->getIntangible()->getBillingPeriodicityType() === PeriodicityTypeEnum::PUNCTUAL){
  264. $this->setEndDate($startDate);
  265. }
  266. return $this;
  267. }
  268. public function setEndDate(\DateTime $endDate = null) {
  269. if(empty($endDate) && !empty($this->getIntangible()) && $this->getIntangible()->getBillingPeriodicityType() === PeriodicityTypeEnum::PUNCTUAL){
  270. return $this;
  271. }
  272. $this->endDate = $endDate;
  273. return $this;
  274. }
  275. }