src/Entity/Commande.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommandeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CommandeRepository::class)
  9. */
  10. class Commande
  11. {
  12. const STATUT_TO_BE_DELETED = "delete";
  13. const STATUT_BROUILLON = "brouillon";
  14. const STATUT_COMPLETE = "complete";
  15. const STATUT_CANCELLED = "annule";
  16. const STATUT_PART = "part";
  17. const STATUT_OPEN = "open";
  18. const NBRE_INSCRIPTION_MAX = 8;
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column(type="string", length=255)
  27. */
  28. private $commandeId;
  29. /**
  30. * @ORM\OneToMany(targetEntity=Inscription::class, mappedBy="commande", fetch="EAGER", cascade={"persist", "remove"})
  31. */
  32. private $inscription;
  33. /**
  34. * @ORM\OneToMany(targetEntity=Compta::class, mappedBy="commande")
  35. */
  36. private $compta;
  37. /**
  38. * @ORM\Column(type="string", length=255, nullable=true)
  39. */
  40. private $statut;
  41. /**
  42. * @ORM\Column(type="datetime")
  43. */
  44. private $dateCreation;
  45. /**
  46. * @ORM\Column(type="datetime",nullable= true)
  47. */
  48. private $dateReminderPaiement;
  49. /**
  50. * @ORM\Column(type="datetime",nullable= true)
  51. */
  52. private $dateReminderDocument;
  53. /**
  54. * @ORM\Column(type="datetime")
  55. */
  56. private $dateModification;
  57. /**
  58. *
  59. * @ORM\OneToMany(targetEntity=ReductionRequest::class, mappedBy="commande", cascade={"persist", "remove"})
  60. */
  61. private $reductionRequest;
  62. /**
  63. * @ORM\ManyToOne(targetEntity=EnterpriseOptionSejourSession::class, inversedBy="commandes", cascade={"persist", "remove"})
  64. */
  65. private $enterpriseOptionSejourSession;
  66. /**
  67. * @ORM\Column(type="text", nullable=true)
  68. */
  69. private $commentaire;
  70. public function __construct()
  71. {
  72. $this->inscription = new ArrayCollection();
  73. $this->reductionRequest = new ArrayCollection();
  74. $this->compta = new ArrayCollection();
  75. $this->dateCreation = new \Datetime();
  76. $this->dateReminderDocument = new \Datetime();
  77. $this->dateReminderPaiement = new \Datetime();
  78. $this->dateModification = new \Datetime();
  79. $this->commandeId = uniqid();
  80. }
  81. public function getId(): ?int
  82. {
  83. return $this->id;
  84. }
  85. public function getCommandeId(): ?string
  86. {
  87. return $this->commandeId;
  88. }
  89. public function setCommandeId(string $commandeId): self
  90. {
  91. $this->commandeId = $commandeId;
  92. return $this;
  93. }
  94. /**
  95. * @return Collection|Inscription[]
  96. */
  97. public function getInscription(): Collection
  98. {
  99. return $this->inscription;
  100. }
  101. public function addInscription(Inscription $inscription): self
  102. {
  103. if (!$this->inscription->contains($inscription)) {
  104. $this->inscription[] = $inscription;
  105. $inscription->setCommande($this);
  106. }
  107. return $this;
  108. }
  109. public function removeInscription(Inscription $inscription): self
  110. {
  111. if ($this->inscription->removeElement($inscription)) {
  112. // set the owning side to null (unless already changed)
  113. if ($inscription->getCommande() === $this) {
  114. $inscription->setCommande(null);
  115. }
  116. }
  117. return $this;
  118. }
  119. /**
  120. * @return Collection|Compta[]
  121. */
  122. public function getCompta(): Collection
  123. {
  124. return $this->compta;
  125. }
  126. public function addComptum(Compta $comptum): self
  127. {
  128. if (!$this->compta->contains($comptum)) {
  129. $this->compta[] = $comptum;
  130. $comptum->setCommande($this);
  131. }
  132. return $this;
  133. }
  134. public function removeComptum(Compta $comptum): self
  135. {
  136. if ($this->compta->removeElement($comptum)) {
  137. // set the owning side to null (unless already changed)
  138. if ($comptum->getCommande() === $this) {
  139. $comptum->setCommande(null);
  140. }
  141. }
  142. return $this;
  143. }
  144. public function getStatut(): ?string
  145. {
  146. return $this->statut;
  147. }
  148. public function setStatut(?string $statut): self
  149. {
  150. $this->statut = $statut;
  151. return $this;
  152. }
  153. public function getDateCreation(): ?\DateTimeInterface
  154. {
  155. $timezone = new \DateTimeZone('Europe/Paris');
  156. $dateCreation = $this->dateCreation;
  157. if ($dateCreation) {
  158. $dateCreation->setTimezone($timezone);
  159. }
  160. return $dateCreation;
  161. }
  162. public function setDateCreation(\DateTimeInterface $dateCreation): self
  163. {
  164. $this->dateCreation = $dateCreation;
  165. return $this;
  166. }
  167. public function getDateReminderPaiement(): ?\DateTimeInterface
  168. {
  169. $timezone = new \DateTimeZone('Europe/Paris');
  170. $dateReminderPaiement = $this->dateReminderPaiement;
  171. if ($dateReminderPaiement) {
  172. $dateReminderPaiement->setTimezone($timezone);
  173. }
  174. return $dateReminderPaiement;
  175. }
  176. public function setDateReminderPaiement(\DateTimeInterface $dateReminderPaiement): self
  177. {
  178. $this->dateReminderPaiement = $dateReminderPaiement;
  179. return $this;
  180. }
  181. public function getDateReminderDocument(): ?\DateTimeInterface
  182. {
  183. $timezone = new \DateTimeZone('Europe/Paris');
  184. $dateReminderDocument = $this->dateReminderDocument;
  185. if ($dateReminderDocument) {
  186. $dateReminderDocument->setTimezone($timezone);
  187. }
  188. return $dateReminderDocument;
  189. }
  190. public function setDateReminderDocument(\DateTimeInterface $dateReminderDocument): self
  191. {
  192. $this->dateReminderDocument = $dateReminderDocument;
  193. return $this;
  194. }
  195. public function getDateModification(): ?\DateTimeInterface
  196. {
  197. $timezone = new \DateTimeZone('Europe/Paris');
  198. $dateModification = $this->dateModification;
  199. if ($dateModification) {
  200. $dateModification->setTimezone($timezone);
  201. }
  202. return $dateModification;
  203. }
  204. public function setDateModification(\DateTimeInterface $dateModification): self
  205. {
  206. $this->dateModification = $dateModification;
  207. return $this;
  208. }
  209. public function getPaiementOverview(): array
  210. {
  211. $output = ['total' => 0, 'reduction' => ['en attente' => 0, 'paid' => 0], 'payment' => ['en attente' => 0, 'paid' => 0]];
  212. foreach ($this->compta as $compta) {
  213. if ($compta->getComptaType() !== null) {
  214. switch ($compta->getComptaType()->getTypeOperation()) {
  215. case 'Cost':
  216. if ($compta->getStatut() !== Compta::STATUT_CANCELLED)
  217. $output['total'] += $compta->getValeur();
  218. break;
  219. case 'Payment':
  220. if ($compta->getStatut() == Compta::STATUT_PART || $compta->getStatut() == Compta::STATUT_COMPLETE) {
  221. $output['payment']['paid'] += $compta->getValeur();
  222. break;
  223. }
  224. if ($compta->getStatut() == Compta::STATUT_OPEN || $compta->getStatut() == Compta::STATUT_PROMESSE) {
  225. $output['payment']['en attente'] += $compta->getValeur();
  226. break;
  227. }
  228. break;
  229. case 'Reduction':
  230. if ($compta->getStatut() == Compta::STATUT_PART || $compta->getStatut() == Compta::STATUT_COMPLETE) {
  231. $output['reduction']['paid'] += $compta->getValeur();
  232. break;
  233. }
  234. if ($compta->getStatut() == Compta::STATUT_OPEN || $compta->getStatut() == Compta::STATUT_PROMESSE) {
  235. $output['reduction']['en attente'] += $compta->getValeur();
  236. break;
  237. }
  238. break;
  239. }
  240. }
  241. }
  242. return $output;
  243. }
  244. public function getOpenInvoice(): float
  245. {
  246. $output = 0;
  247. foreach ($this->compta as $compta) {
  248. if ($compta->getStatut() !== "annulé")
  249. $output += $compta->getValeur();
  250. }
  251. return $output;
  252. }
  253. public function getAllSolde(): float
  254. {
  255. $output = 0;
  256. foreach ($this->compta as $compta) {
  257. if ($compta->getStatut() !== "annulé" && $compta->getStatut() !== "promesse")
  258. $output += $compta->getValeur();
  259. }
  260. return $output;
  261. }
  262. public function getTotalPrice(): float
  263. {
  264. $output = 0;
  265. foreach ($this->compta as $compta) {
  266. if ($compta->getType() !== "acompte" && $compta->getType() !== "solde")
  267. $output += $compta->getValeur();
  268. }
  269. return $output;
  270. }
  271. public function getTotalPrice2(): float
  272. {
  273. $output = 0;
  274. foreach ($this->compta as $compta) {
  275. if ( $compta->getType() == "total"){
  276. $output += $compta->getValeur();
  277. }
  278. }
  279. return $output;
  280. }
  281. /**
  282. * @return Collection|Inscription[]
  283. */
  284. public function getReductionRequest(): Collection
  285. {
  286. return $this->reductionRequest;
  287. }
  288. public function addReductionRequest(ReductionRequest $inscription): self
  289. {
  290. if (!$this->reductionRequest->contains($inscription)) {
  291. $this->reductionRequest[] = $inscription;
  292. $inscription->setCommande($this);
  293. }
  294. return $this;
  295. }
  296. public function removeReductionRequest(ReductionRequest $inscription): self
  297. {
  298. if ($this->reductionRequest->removeElement($inscription)) {
  299. // set the owning side to null (unless already changed)
  300. if ($inscription->getCommande() === $this) {
  301. $inscription->setCommande(null);
  302. }
  303. }
  304. return $this;
  305. }
  306. private function addValueOrCreateKey(string $key, mixed $value, array $array): array
  307. {
  308. if (array_key_exists($key, $array)) {
  309. $array[$key] += $value;
  310. return $array;
  311. }
  312. $array[$key] = $value;
  313. return $array;
  314. }
  315. public function getNombreInscription(): int
  316. {
  317. return count($this->inscription);
  318. }
  319. public function getEnterpriseOptionSejourSession(): ?EnterpriseOptionSejourSession
  320. {
  321. return $this->enterpriseOptionSejourSession;
  322. }
  323. public function setEnterpriseOptionSejourSession(?EnterpriseOptionSejourSession $enterpriseOptionSejourSession): self
  324. {
  325. $this->enterpriseOptionSejourSession = $enterpriseOptionSejourSession;
  326. return $this;
  327. }
  328. public function getCommentaire(): ?string
  329. {
  330. return $this->commentaire;
  331. }
  332. public function setCommentaire(?string $commentaire): self
  333. {
  334. $this->commentaire = $commentaire;
  335. return $this;
  336. }
  337. }