src/Entity/Transaction.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9. * Transaction
  10. *
  11. * @ORM\Table(name="Transaction")
  12. * @ORM\Entity(repositoryClass="App\Entity\TransactionRepository")
  13. * @UniqueEntity(fields={"invoiceNumber"})
  14. */
  15. class Transaction
  16. {
  17. public static function createWithId($id)
  18. {
  19. $instance = new self();
  20. $instance->id = $id;
  21. return $instance;
  22. }
  23. /**
  24. * @var integer
  25. *
  26. * @ORM\Column(name="id", type="integer")
  27. * @ORM\Id
  28. * @ORM\GeneratedValue(strategy="AUTO")
  29. */
  30. private $id;
  31. /**
  32. * @var DateTime
  33. *
  34. * @ORM\Column(name="transaction_date", type="datetime", nullable=true)
  35. */
  36. private $date;
  37. /**
  38. * If price is not null, the transaction is considered an invoice
  39. *
  40. * @var integer
  41. *
  42. * @ORM\Column(name="prix", type="integer", nullable=true)
  43. */
  44. private $prix;
  45. /**
  46. * @var integer
  47. *
  48. * @ORM\Column(name="credits", type="integer", nullable=true)
  49. */
  50. private $credits;
  51. /**
  52. * @var boolean
  53. *
  54. * @ORM\Column(name="is_cart", type="boolean")
  55. */
  56. private $cart;
  57. /**
  58. * @var boolean
  59. *
  60. * @ORM\Column(name="is_confirmed", type="boolean")
  61. */
  62. private $confirmed;
  63. /**
  64. * @var string
  65. *
  66. * @ORM\Column(name="invoice_number", type="string", length=255, nullable=true, unique=true)
  67. */
  68. private $invoiceNumber;
  69. /**
  70. * @var array
  71. *
  72. * @ORM\Column(name="demande_ids", type="simple_array", nullable=true)
  73. */
  74. private $demandeIds;
  75. /**
  76. * @var ArrayCollection
  77. *
  78. * @ORM\ManyToMany(targetEntity="Demande", inversedBy="transactions")
  79. * @ORM\JoinTable(name="TransactionDemande")
  80. */
  81. private $demandes;
  82. /**
  83. * @var ?Prestataire
  84. *
  85. * @ORM\ManyToOne(targetEntity="Prestataire", inversedBy="transactions")
  86. * @ORM\JoinColumn(name="prestataire_id", referencedColumnName="id", nullable=true)
  87. */
  88. private ?Prestataire $prestataire;
  89. /**
  90. * @var ?Order
  91. * @ORM\OneToOne(targetEntity="Order")
  92. * @ORM\JoinColumn(name="order_id", referencedColumnName="id", nullable=true, unique=true, onDelete="SET NULL")
  93. */
  94. #[ORM\OneToOne(targetEntity: Order::class)]
  95. #[ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id', nullable: true, unique: true, onDelete: 'SET NULL')]
  96. private ?Order $order = null;
  97. /**
  98. * Constructor
  99. */
  100. public function __construct()
  101. {
  102. $this->demandes = new ArrayCollection();
  103. $this->demandeIds = array();
  104. $this->cart = 0;
  105. }
  106. /**
  107. * Get id
  108. *
  109. * @return integer
  110. */
  111. public function getId()
  112. {
  113. return $this->id;
  114. }
  115. /**
  116. * Set date
  117. *
  118. * @param DateTime $date
  119. *
  120. * @return Transaction
  121. */
  122. public function setDate($date)
  123. {
  124. $this->date = $date;
  125. return $this;
  126. }
  127. /**
  128. * Get date
  129. *
  130. * @return DateTime
  131. */
  132. public function getDate()
  133. {
  134. return $this->date;
  135. }
  136. /**
  137. * Set prix
  138. *
  139. * @param integer $prix
  140. *
  141. * @return Transaction
  142. */
  143. public function setPrix($prix)
  144. {
  145. $this->prix = $prix;
  146. return $this;
  147. }
  148. /**
  149. * Get prix
  150. *
  151. * @return integer
  152. */
  153. public function getPrix()
  154. {
  155. return $this->prix;
  156. }
  157. /**
  158. * Set credits
  159. *
  160. * @param integer $credits
  161. *
  162. * @return Transaction
  163. */
  164. public function setCredits($credits)
  165. {
  166. $this->credits = $credits;
  167. return $this;
  168. }
  169. /**
  170. * Get credits
  171. *
  172. * @return integer
  173. */
  174. public function getCredits()
  175. {
  176. return $this->credits;
  177. }
  178. /**
  179. * @param boolean $cart
  180. *
  181. * @return Transaction
  182. */
  183. public function setCart($cart)
  184. {
  185. $this->cart = $cart;
  186. return $this;
  187. }
  188. /**
  189. * @return boolean
  190. */
  191. public function isCart()
  192. {
  193. return $this->cart;
  194. }
  195. /**
  196. * @param boolean $confirmed
  197. *
  198. * @return Transaction
  199. */
  200. public function setConfirmed($confirmed)
  201. {
  202. $this->confirmed = $confirmed;
  203. return $this;
  204. }
  205. /**
  206. * @return boolean
  207. */
  208. public function isConfirmed()
  209. {
  210. return $this->confirmed;
  211. }
  212. /**
  213. * @param Demande $demande
  214. *
  215. * @return Transaction
  216. */
  217. public function addDemande(Demande $demande)
  218. {
  219. $this->demandes[] = $demande;
  220. $this->addDemandeId($demande->getId());
  221. return $this;
  222. }
  223. /**
  224. * @param Demande $demande
  225. */
  226. public function removeDemande(Demande $demande)
  227. {
  228. $this->demandes->removeElement($demande);
  229. $this->removeDemandeId($demande->getId());
  230. }
  231. /**
  232. * @return Collection
  233. */
  234. public function getDemandes()
  235. {
  236. return $this->demandes;
  237. }
  238. /**
  239. * @param ?Prestataire $prestataire
  240. *
  241. * @return Transaction
  242. */
  243. public function setPrestataire(?Prestataire $prestataire = null)
  244. {
  245. $this->prestataire = $prestataire;
  246. return $this;
  247. }
  248. /**
  249. * @return ?Prestataire
  250. */
  251. public function getPrestataire()
  252. {
  253. return $this->prestataire;
  254. }
  255. public function getOrder(): ?Order
  256. {
  257. return $this->order;
  258. }
  259. public function setOrder(?Order $order): self
  260. {
  261. $this->order = $order;
  262. return $this;
  263. }
  264. /**
  265. * @param array $demandeIds
  266. * @return Transaction
  267. */
  268. public function setDemandeIds($demandeIds)
  269. {
  270. $this->demandeIds = $demandeIds;
  271. return $this;
  272. }
  273. /**
  274. * @return array
  275. */
  276. public function getDemandeIds()
  277. {
  278. return $this->demandeIds;
  279. }
  280. public function addDemandeId($demandeId)
  281. {
  282. $demandeIds = $this->getDemandeIds();
  283. $demandeIds[] = $demandeId;
  284. $this->setDemandeIds(array_unique($demandeIds));
  285. }
  286. public function removeDemandeId($demandeId)
  287. {
  288. $demandeIds = $this->getDemandeIds();
  289. $offset = array_search($demandeId, $demandeIds);
  290. if ($offset !== false) {
  291. unset($demandeIds[$offset]);
  292. $this->setDemandeIds($demandeIds);
  293. }
  294. }
  295. public function getDemandesForDisplay()
  296. {
  297. $demandes = array();
  298. foreach ($this->getDemandeIds() as $demandeId) {
  299. $demandes[$demandeId] = $demandeId;
  300. }
  301. foreach ($this->getDemandes() as $demande) {
  302. $demandes[$demande->getId()] = $demande;
  303. }
  304. return $demandes;
  305. }
  306. /**
  307. * Get cart
  308. *
  309. * @return boolean
  310. */
  311. public function getCart()
  312. {
  313. return $this->cart;
  314. }
  315. /**
  316. * Get confirmed
  317. *
  318. * @return boolean
  319. */
  320. public function getConfirmed()
  321. {
  322. return $this->confirmed;
  323. }
  324. /**
  325. * @return string
  326. */
  327. public function getInvoiceNumber()
  328. {
  329. return $this->invoiceNumber;
  330. }
  331. public function getInvoiceFilename()
  332. {
  333. return sprintf('exacompare-facture-%s.pdf', $this->getInvoiceNumber());
  334. }
  335. /**
  336. * @param string $invoiceNumber
  337. */
  338. public function setInvoiceNumber($invoiceNumber)
  339. {
  340. $this->invoiceNumber = $invoiceNumber;
  341. }
  342. }