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 Payment
  91. */
  92. private $payment;
  93. /**
  94. * Constructor
  95. */
  96. public function __construct()
  97. {
  98. $this->demandes = new ArrayCollection();
  99. $this->demandeIds = array();
  100. $this->cart = 0;
  101. }
  102. /**
  103. * Get id
  104. *
  105. * @return integer
  106. */
  107. public function getId()
  108. {
  109. return $this->id;
  110. }
  111. /**
  112. * Set date
  113. *
  114. * @param DateTime $date
  115. *
  116. * @return Transaction
  117. */
  118. public function setDate($date)
  119. {
  120. $this->date = $date;
  121. return $this;
  122. }
  123. /**
  124. * Get date
  125. *
  126. * @return DateTime
  127. */
  128. public function getDate()
  129. {
  130. return $this->date;
  131. }
  132. /**
  133. * Set prix
  134. *
  135. * @param integer $prix
  136. *
  137. * @return Transaction
  138. */
  139. public function setPrix($prix)
  140. {
  141. $this->prix = $prix;
  142. return $this;
  143. }
  144. /**
  145. * Get prix
  146. *
  147. * @return integer
  148. */
  149. public function getPrix()
  150. {
  151. return $this->prix;
  152. }
  153. /**
  154. * Set credits
  155. *
  156. * @param integer $credits
  157. *
  158. * @return Transaction
  159. */
  160. public function setCredits($credits)
  161. {
  162. $this->credits = $credits;
  163. return $this;
  164. }
  165. /**
  166. * Get credits
  167. *
  168. * @return integer
  169. */
  170. public function getCredits()
  171. {
  172. return $this->credits;
  173. }
  174. /**
  175. * @param boolean $cart
  176. *
  177. * @return Transaction
  178. */
  179. public function setCart($cart)
  180. {
  181. $this->cart = $cart;
  182. return $this;
  183. }
  184. /**
  185. * @return boolean
  186. */
  187. public function isCart()
  188. {
  189. return $this->cart;
  190. }
  191. /**
  192. * @param boolean $confirmed
  193. *
  194. * @return Transaction
  195. */
  196. public function setConfirmed($confirmed)
  197. {
  198. $this->confirmed = $confirmed;
  199. return $this;
  200. }
  201. /**
  202. * @return boolean
  203. */
  204. public function isConfirmed()
  205. {
  206. return $this->confirmed;
  207. }
  208. /**
  209. * @param Demande $demande
  210. *
  211. * @return Transaction
  212. */
  213. public function addDemande(Demande $demande)
  214. {
  215. $this->demandes[] = $demande;
  216. $this->addDemandeId($demande->getId());
  217. return $this;
  218. }
  219. /**
  220. * @param Demande $demande
  221. */
  222. public function removeDemande(Demande $demande)
  223. {
  224. $this->demandes->removeElement($demande);
  225. $this->removeDemandeId($demande->getId());
  226. }
  227. /**
  228. * @return Collection
  229. */
  230. public function getDemandes()
  231. {
  232. return $this->demandes;
  233. }
  234. /**
  235. * @param ?Prestataire $prestataire
  236. *
  237. * @return Transaction
  238. */
  239. public function setPrestataire(?Prestataire $prestataire = null)
  240. {
  241. $this->prestataire = $prestataire;
  242. return $this;
  243. }
  244. /**
  245. * @return ?Prestataire
  246. */
  247. public function getPrestataire()
  248. {
  249. return $this->prestataire;
  250. }
  251. /**
  252. * @return mixed
  253. */
  254. public function getPayment()
  255. {
  256. return $this->payment;
  257. }
  258. /**
  259. * @param mixed $payment
  260. */
  261. public function setPayment($payment)
  262. {
  263. $this->payment = $payment;
  264. }
  265. /**
  266. * @param array $demandeIds
  267. * @return Transaction
  268. */
  269. public function setDemandeIds($demandeIds)
  270. {
  271. $this->demandeIds = $demandeIds;
  272. return $this;
  273. }
  274. /**
  275. * @return array
  276. */
  277. public function getDemandeIds()
  278. {
  279. return $this->demandeIds;
  280. }
  281. public function addDemandeId($demandeId)
  282. {
  283. $demandeIds = $this->getDemandeIds();
  284. $demandeIds[] = $demandeId;
  285. $this->setDemandeIds(array_unique($demandeIds));
  286. }
  287. public function removeDemandeId($demandeId)
  288. {
  289. $demandeIds = $this->getDemandeIds();
  290. $offset = array_search($demandeId, $demandeIds);
  291. if ($offset !== false) {
  292. unset($demandeIds[$offset]);
  293. $this->setDemandeIds($demandeIds);
  294. }
  295. }
  296. public function getDemandesForDisplay()
  297. {
  298. $demandes = array();
  299. foreach ($this->getDemandeIds() as $demandeId) {
  300. $demandes[$demandeId] = $demandeId;
  301. }
  302. foreach ($this->getDemandes() as $demande) {
  303. $demandes[$demande->getId()] = $demande;
  304. }
  305. return $demandes;
  306. }
  307. /**
  308. * Get cart
  309. *
  310. * @return boolean
  311. */
  312. public function getCart()
  313. {
  314. return $this->cart;
  315. }
  316. /**
  317. * Get confirmed
  318. *
  319. * @return boolean
  320. */
  321. public function getConfirmed()
  322. {
  323. return $this->confirmed;
  324. }
  325. /**
  326. * @return string
  327. */
  328. public function getInvoiceNumber()
  329. {
  330. return $this->invoiceNumber;
  331. }
  332. public function getInvoiceFilename()
  333. {
  334. return sprintf('exacompare-facture-%s.pdf', $this->getInvoiceNumber());
  335. }
  336. /**
  337. * @param string $invoiceNumber
  338. */
  339. public function setInvoiceNumber($invoiceNumber)
  340. {
  341. $this->invoiceNumber = $invoiceNumber;
  342. }
  343. }