src/Entity/System/SubscriptionLine.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * SubscriptionLine
  8. *
  9. * @ORM\Table(name="subscriptions_lines", indexes={
  10. *
  11. * @ORM\Index(name="name", columns={"name"})
  12. * })
  13. *
  14. * @ORM\Entity(repositoryClass="App\Repository\System\SubscriptionLineRepository")
  15. */
  16. class SubscriptionLine
  17. {
  18. public const MANUAL_CHANGE = 'Cambio manual';
  19. public const CANCEL_NAME_VALUE = 'Cancel';
  20. public const BASIC_NAME_VALUE = 'Basic';
  21. /**
  22. * @var int
  23. *
  24. * @ORM\Id
  25. *
  26. * @ORM\GeneratedValue(strategy="AUTO")
  27. *
  28. * @ORM\Column(type="integer", name="id_subscription_lines")
  29. */
  30. private $id;
  31. /**
  32. * @var Subscription
  33. *
  34. * @ORM\ManyToOne(targetEntity="App\Entity\System\Subscription", inversedBy="subscriptionLines")
  35. *
  36. * @ORM\JoinColumn(referencedColumnName="id_subscription", name="id_subscription", nullable=false)
  37. */
  38. private $subscription;
  39. /**
  40. * @var Collection<int, SubscriptionLineHistory>&iterable<SubscriptionLineHistory>
  41. *
  42. * @ORM\OneToMany(targetEntity="SubscriptionLineHistory", mappedBy="subscriptionLine", cascade={"persist"})
  43. */
  44. private $subscriptionLineHistories;
  45. /**
  46. * @var SubscriptionGroup
  47. *
  48. * @ORM\ManyToOne(targetEntity="App\Entity\System\SubscriptionGroup", inversedBy="subscriptionLines")
  49. *
  50. * @ORM\JoinColumn(referencedColumnName="id_group", name="id_group", nullable=false)
  51. */
  52. private $group;
  53. /**
  54. * @var string|null
  55. *
  56. * @ORM\Column(type="string", length=100, nullable=true)
  57. */
  58. private $name;
  59. /**
  60. * @var \DateTime
  61. *
  62. * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  63. */
  64. private $dateCreate;
  65. /**
  66. * @var Customer|null
  67. *
  68. * @ORM\ManyToOne(targetEntity="App\Entity\System\Customer", inversedBy="subscriptionLines")
  69. *
  70. * @ORM\JoinColumn(referencedColumnName="id_customer", name="id_customer")
  71. */
  72. private $customer;
  73. /**
  74. * @var \DateTime|null
  75. *
  76. * @ORM\Column(type="datetime", nullable=true)
  77. */
  78. private $dateDue;
  79. /**
  80. * @var float|null
  81. *
  82. * @ORM\Column(type="float", nullable=true)
  83. */
  84. private $cost;
  85. /**
  86. * @var int
  87. *
  88. * @ORM\Column(type="integer", nullable=false)
  89. */
  90. private $userCreate;
  91. /**
  92. * @var int
  93. *
  94. * @ORM\Column(type="integer", nullable=false)
  95. */
  96. private $userMod;
  97. /**
  98. * @var int|null
  99. *
  100. * @ORM\Column(name="nintentos", type="integer", options={"default" : 0}, nullable=true)
  101. */
  102. private ?int $numberAttempts = 0;
  103. /**
  104. * @var int
  105. *
  106. * @ORM\Column(type="integer", options={"default" : 0}, nullable=false)
  107. */
  108. private int $cycles = 0;
  109. /**
  110. * @var int
  111. *
  112. * @ORM\Column(type="integer", nullable=false, options={"default": 0})
  113. */
  114. private int $numCycles = 0;
  115. /**
  116. * @var string|null
  117. *
  118. * @ORM\Column(name="id_transaction", type="string", length=50, nullable=true)
  119. */
  120. private $transaction;
  121. /**
  122. * @var Collection<int, SubscriptionCustomer>&iterable<int, SubscriptionCustomer>
  123. *
  124. * @ORM\OneToMany(targetEntity="App\Entity\System\SubscriptionCustomer", mappedBy="subscriptionLine", cascade={"persist"})
  125. */
  126. private $subscriptionCustomers;
  127. /**
  128. * @ORM\Column(type="boolean", nullable=false, options={"default": 0})
  129. */
  130. private bool $migrated = false;
  131. /**
  132. * @ORM\Column(type="string", length=64, name="internal_migration_status", nullable=true)
  133. */
  134. private ?string $internalMigrationStatus;
  135. /**
  136. * @return int
  137. */
  138. public function getId(): int
  139. {
  140. return $this->id;
  141. }
  142. /**
  143. * @return Subscription
  144. */
  145. public function getSubscription(): Subscription
  146. {
  147. return $this->subscription;
  148. }
  149. /**
  150. * @param Subscription $subscription
  151. *
  152. * @return SubscriptionLine
  153. */
  154. public function setSubscription(Subscription $subscription): SubscriptionLine
  155. {
  156. $this->subscription = $subscription;
  157. return $this;
  158. }
  159. /**
  160. * @return SubscriptionGroup
  161. */
  162. public function getGroup(): SubscriptionGroup
  163. {
  164. return $this->group;
  165. }
  166. /**
  167. * @param SubscriptionGroup $group
  168. *
  169. * @return SubscriptionLine
  170. */
  171. public function setGroup(SubscriptionGroup $group): SubscriptionLine
  172. {
  173. $this->group = $group;
  174. return $this;
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function getName(): string
  180. {
  181. return $this->name;
  182. }
  183. /**
  184. * @param string|null $name
  185. *
  186. * @return SubscriptionLine
  187. */
  188. public function setName(?string $name): SubscriptionLine
  189. {
  190. $this->name = $name;
  191. return $this;
  192. }
  193. /**
  194. * @return \DateTime
  195. */
  196. public function getDateCreate(): \DateTime
  197. {
  198. return $this->dateCreate;
  199. }
  200. /**
  201. * @param \DateTime $dateCreate
  202. *
  203. * @return SubscriptionLine
  204. */
  205. public function setDateCreate(\DateTime $dateCreate): SubscriptionLine
  206. {
  207. $this->dateCreate = $dateCreate;
  208. return $this;
  209. }
  210. /**
  211. * @return Customer
  212. */
  213. public function getCustomer(): Customer
  214. {
  215. return $this->customer;
  216. }
  217. /**
  218. * @param Customer|null $customer
  219. *
  220. * @return SubscriptionLine
  221. */
  222. public function setCustomer(?Customer $customer): SubscriptionLine
  223. {
  224. $this->customer = $customer;
  225. return $this;
  226. }
  227. /**
  228. * @return \DateTime
  229. */
  230. public function getDateDue(): ?\DateTime
  231. {
  232. return $this->dateDue;
  233. }
  234. /**
  235. * @param \DateTime|null $dateDue
  236. *
  237. * @return SubscriptionLine
  238. */
  239. public function setDateDue(?\DateTime $dateDue): SubscriptionLine
  240. {
  241. $this->dateDue = $dateDue;
  242. return $this;
  243. }
  244. /**
  245. * @return float
  246. */
  247. public function getCost(): float
  248. {
  249. return $this->cost;
  250. }
  251. /**
  252. * @param float|null $cost
  253. *
  254. * @return SubscriptionLine
  255. */
  256. public function setCost(?float $cost): SubscriptionLine
  257. {
  258. $this->cost = $cost;
  259. return $this;
  260. }
  261. /**
  262. * @return int
  263. */
  264. public function getUserCreate(): int
  265. {
  266. return $this->userCreate;
  267. }
  268. /**
  269. * @param int $userCreate
  270. *
  271. * @return SubscriptionLine
  272. */
  273. public function setUserCreate(int $userCreate): SubscriptionLine
  274. {
  275. $this->userCreate = $userCreate;
  276. return $this;
  277. }
  278. /**
  279. * @return int
  280. */
  281. public function getUserMod(): int
  282. {
  283. return $this->userMod;
  284. }
  285. /**
  286. * @param int $userMod
  287. *
  288. * @return SubscriptionLine
  289. */
  290. public function setUserMod(int $userMod): SubscriptionLine
  291. {
  292. $this->userMod = $userMod;
  293. return $this;
  294. }
  295. /**
  296. * @return int|null
  297. */
  298. public function getNumberAttempts(): ?int
  299. {
  300. return $this->numberAttempts;
  301. }
  302. /**
  303. * @param int|null $numberAttempts
  304. *
  305. * @return SubscriptionLine
  306. */
  307. public function setNumberAttempts(?int $numberAttempts): SubscriptionLine
  308. {
  309. $this->numberAttempts = $numberAttempts;
  310. return $this;
  311. }
  312. public function getCycles(): int
  313. {
  314. return $this->cycles;
  315. }
  316. public function setCycles(int $cycles): SubscriptionLine
  317. {
  318. $this->cycles = $cycles;
  319. return $this;
  320. }
  321. /**
  322. * @return int|null
  323. */
  324. public function getNumCycles(): ?int
  325. {
  326. return $this->numCycles;
  327. }
  328. /**
  329. * @param int|null $numCycles
  330. *
  331. * @return SubscriptionLine
  332. */
  333. public function setNumCycles(?int $numCycles): SubscriptionLine
  334. {
  335. $this->numCycles = $numCycles;
  336. return $this;
  337. }
  338. /**
  339. * @return string|null
  340. */
  341. public function getTransaction(): ?string
  342. {
  343. return $this->transaction;
  344. }
  345. /**
  346. * @param string|null $transaction
  347. *
  348. * @return SubscriptionLine
  349. */
  350. public function setTransaction(?string $transaction): SubscriptionLine
  351. {
  352. $this->transaction = $transaction;
  353. return $this;
  354. }
  355. public function cancelSubscriptionLine(): void
  356. {
  357. $this->name = self::CANCEL_NAME_VALUE;
  358. $this->dateDue = null;
  359. }
  360. public function incrementNumberAttempts(int $days): void
  361. {
  362. $this->numberAttempts++;
  363. if ($this->dateDue === null) {
  364. $this->dateDue = new \DateTime();
  365. }
  366. $this->dateDue->modify("+$days Days");
  367. }
  368. public function isMigrated(): bool
  369. {
  370. return $this->migrated;
  371. }
  372. public function setMigrated(bool $migrated): SubscriptionLine
  373. {
  374. $this->migrated = $migrated;
  375. return $this;
  376. }
  377. /**
  378. * @return array|ArrayCollection<int, SubscriptionCustomer>
  379. */
  380. public function getSubscriptionCustomers()
  381. {
  382. return $this->subscriptionCustomers;
  383. }
  384. /**
  385. * @param Collection<int, SubscriptionCustomer>&iterable<int, SubscriptionCustomer> $subscriptionCustomers
  386. *
  387. * @return $this
  388. */
  389. public function setSubscriptionCustomers($subscriptionCustomers): SubscriptionLine
  390. {
  391. $this->subscriptionCustomers = $subscriptionCustomers;
  392. return $this;
  393. }
  394. public function getInternalMigrationStatus(): ?string
  395. {
  396. return $this->internalMigrationStatus;
  397. }
  398. public function setInternalMigrationStatus(?string $internalMigrationStatus): SubscriptionLine
  399. {
  400. $this->internalMigrationStatus = $internalMigrationStatus;
  401. return $this;
  402. }
  403. public function setSubscriptionToMigrated(): self
  404. {
  405. $this->migrated = true;
  406. $this->internalMigrationStatus = 'migrated';
  407. return $this;
  408. }
  409. /**
  410. * @return SubscriptionLineHistory[]|ArrayCollection<int, SubscriptionLineHistory>
  411. */
  412. public function getSubscriptionLineHistories()
  413. {
  414. return $this->subscriptionLineHistories;
  415. }
  416. /**
  417. * @param SubscriptionLineHistory[]|ArrayCollection<int, SubscriptionLineHistory> $subscriptionLineHistories
  418. */
  419. public function setSubscriptionLineHistories($subscriptionLineHistories): SubscriptionLine
  420. {
  421. $this->subscriptionLineHistories = $subscriptionLineHistories;
  422. return $this;
  423. }
  424. }