<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\SubscriptionOrderRepository")
* @ORM\HasLifecycleCallbacks()
*/
class SubscriptionOrder
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Child", inversedBy="subscriptionOrders")
*/
private $participant;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="subscriptionOrders")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="string", length=255)
*/
private $customerId;
/**
* @ORM\Column(type="datetime")
*/
private $purchaseDate;
/**
* @ORM\Column(type="datetime", nullable=true)
* use for track schedules change and limit the changes for 30 days
*/
private $updateAt;
/**
* @ORM\Column(type="boolean")
*/
private $isActif;
/**
* @ORM\OneToMany(targetEntity="App\Entity\TeacherSchedule", mappedBy="subscriptionOrder")
*/
private $schedules;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Plan", inversedBy="subscriptionOrders")
* @ORM\JoinColumn(nullable=false)
*/
private $plan;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Teacher", inversedBy="subscriptionOrders")
* @ORM\JoinColumn(nullable=false)
*/
private $teacher;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="subscriptionOrders")
* @ORM\JoinColumn(nullable=false)
*/
private $category;
/**
* @ORM\Column(type="datetime")
*/
private $coursesStartAt;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Subject", inversedBy="subscriptionOrders")
*/
private $subject;
/**
* @ORM\Column(type="integer")
*/
private $catchUpRight;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $nextPaymentDate;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PaidCourseList", mappedBy="subscriptionOrder")
*/
private $coursesList;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $cardBrand;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $cardLast4;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeSubscriptionId;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $renewBefore;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isCancelled;
/**
* @ORM\Column(type="integer")
*/
private $nbOfScheduleChoose = 1;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isDue;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nextPaymentTimeStamp;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastPaidCourse;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PlanUpdateLog", mappedBy="subscription")
*/
private $planUpdateLogs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\AbsenceLog", mappedBy="subscription")
*/
private $absenceLogs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SubscriptionLessonReport", mappedBy="subscription", orphanRemoval=true)
*/
private $subscriptionLessonReports;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $cancellationDate;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\SubjectLevel", inversedBy="subscriptionOrder")
*/
private $subjectLevel;
/**
* @ORM\Column(type="decimal", precision=25, scale=15)
*/
private $paidAmount;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $TotalLostMinutes;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Homework", mappedBy="RelatedToSubscription")
*/
private $homeworks;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $haveRamadanCredit;
/**
* @ORM\Column(type="decimal", precision=25, scale=15, nullable=true)
*/
private $ramadanCreditAmount;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ActiveCampainSubscribeLostLog", mappedBy="subscription")
*/
private $subscribeLostLogs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ActiveCampainUnsubscribeLog", mappedBy="subscription")
*/
private $unsubscribeLogs;
/**
* @ORM\OneToMany(targetEntity=Exam::class, mappedBy="relatedToSubscription")
*/
private $exams;
/**
* @ORM\OneToMany(targetEntity=TrainingReport::class, mappedBy="relatedToSubscription")
*/
private $trainingReports;
public function __construct()
{
$this->schedules = new ArrayCollection();
$this->coursesList = new ArrayCollection();
$this->planUpdateLogs = new ArrayCollection();
$this->absenceLogs = new ArrayCollection();
$this->subscriptionLessonReports = new ArrayCollection();
$this->homeworks = new ArrayCollection();
$this->subscribeLostLogs = new ArrayCollection();
$this->unsubscribeLogs = new ArrayCollection();
$this->exams = new ArrayCollection();
$this->trainingReports = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPurchaseDate(): ?\DateTimeInterface
{
return $this->purchaseDate;
}
public function setPurchaseDate(\DateTimeInterface $purchaseDate): self
{
$this->purchaseDate = $purchaseDate;
return $this;
}
public function getCustomerId(): ?string
{
return $this->customerId;
}
public function setCustomerId(string $customerId): self
{
$this->customerId = $customerId;
return $this;
}
public function getUpdateAt(): ?\DateTimeInterface
{
return $this->updateAt;
}
public function setUpdateAt(?\DateTimeInterface $updateAt): self
{
$this->updateAt = $updateAt;
return $this;
}
public function getIsActif(): ?bool
{
return $this->isActif;
}
public function setIsActif(bool $isActif): self
{
$this->isActif = $isActif;
return $this;
}
public function getParticipant(): ?Child
{
return $this->participant;
}
public function setParticipant(?Child $participant): self
{
$this->participant = $participant;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|TeacherSchedule[]
*/
public function getSchedules(): Collection
{
return $this->schedules;
}
public function addSchedule(TeacherSchedule $schedule): self
{
if (!$this->schedules->contains($schedule)) {
$this->schedules[] = $schedule;
$schedule->setSubscriptionOrder($this);
}
return $this;
}
public function removeSchedule(TeacherSchedule $schedule): self
{
if ($this->schedules->contains($schedule)) {
$this->schedules->removeElement($schedule);
// set the owning side to null (unless already changed)
if ($schedule->getSubscriptionOrder() === $this) {
$schedule->setSubscriptionOrder(null);
}
}
return $this;
}
public function getPlan(): ?Plan
{
return $this->plan;
}
public function setPlan(?Plan $plan): self
{
$this->plan = $plan;
return $this;
}
public function getTeacher(): ?Teacher
{
return $this->teacher;
}
public function setTeacher(?Teacher $teacher): self
{
$this->teacher = $teacher;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getCoursesStartAt(): ?\DateTimeInterface
{
return $this->coursesStartAt;
}
public function setCoursesStartAt(\DateTimeInterface $coursesStartAt): self
{
$this->coursesStartAt = $coursesStartAt;
return $this;
}
public function getSubject(): ?Subject
{
return $this->subject;
}
public function setSubject(?Subject $subject): self
{
$this->subject = $subject;
return $this;
}
public function getCatchUpRight(): ?int
{
return $this->catchUpRight;
}
public function setCatchUpRight(int $catchUpRight): self
{
$this->catchUpRight = $catchUpRight;
return $this;
}
public function getNextPaymentDate(): ?\DateTimeInterface
{
return $this->nextPaymentDate;
}
public function setNextPaymentDate(?\DateTimeInterface $nextPaymentDate): self
{
$this->nextPaymentDate = $nextPaymentDate;
return $this;
}
/**
* @return Collection|PaidCourseList[]
*/
public function getCoursesList(): Collection
{
return $this->coursesList;
}
public function addCoursesList(PaidCourseList $coursesList): self
{
if (!$this->coursesList->contains($coursesList)) {
$this->coursesList[] = $coursesList;
$coursesList->setSubscriptionOrder($this);
}
return $this;
}
public function removeCoursesList(PaidCourseList $coursesList): self
{
if ($this->coursesList->contains($coursesList)) {
$this->coursesList->removeElement($coursesList);
// set the owning side to null (unless already changed)
if ($coursesList->getSubscriptionOrder() === $this) {
$coursesList->setSubscriptionOrder(null);
}
}
return $this;
}
public function getCardBrand(): ?string
{
return $this->cardBrand;
}
public function setCardBrand(?string $cardBrand): self
{
$this->cardBrand = $cardBrand;
return $this;
}
public function getCardLast4(): ?string
{
return $this->cardLast4;
}
public function setCardLast4(?string $cardLast4): self
{
$this->cardLast4 = $cardLast4;
return $this;
}
public function getStripeSubscriptionId(): ?string
{
return $this->stripeSubscriptionId;
}
public function setStripeSubscriptionId(?string $stripeSubscriptionId): self
{
$this->stripeSubscriptionId = $stripeSubscriptionId;
return $this;
}
public function getRenewBefore(): ?\DateTimeInterface
{
return $this->renewBefore;
}
public function setRenewBefore(?\DateTimeInterface $renewBefore): self
{
$this->renewBefore = $renewBefore;
return $this;
}
public function cancel()
{
$this->isActif = false;
}
public function makeDue()
{
$this->isDue = true;
}
public function fullyCancel()
{
$this->isActif = false;
$this->isCancelled = true;
$this->isDue = false;
$this->cancellationDate = new \DateTimeImmutable();
}
public function reactivate()
{
$this->isActif = true;
}
public function getIsCancelled(): ?bool
{
return $this->isCancelled;
}
public function setIsCancelled(?bool $isCancelled): self
{
$this->isCancelled = $isCancelled;
return $this;
}
public function getNbOfScheduleChoose(): int
{
return $this->nbOfScheduleChoose;
}
public function setNbOfScheduleChoose(int $nbOfScheduleChoose): self
{
$this->nbOfScheduleChoose = $nbOfScheduleChoose;
return $this;
}
public function getIsDue(): ?bool
{
return $this->isDue;
}
public function setIsDue(?bool $isDue): self
{
$this->isDue = $isDue;
return $this;
}
public function getNextPaymentTimeStamp(): ?string
{
return $this->nextPaymentTimeStamp;
}
public function setNextPaymentTimeStamp(?string $nextPaymentTimeStamp): self
{
$this->nextPaymentTimeStamp = $nextPaymentTimeStamp;
return $this;
}
public function getLastPaidCourse(): ?\DateTimeInterface
{
return $this->lastPaidCourse;
}
public function setLastPaidCourse(?\DateTimeInterface $lastPaidCourse): self
{
$this->lastPaidCourse = $lastPaidCourse;
return $this;
}
/**
* @return Collection|PlanUpdateLog[]
*/
public function getPlanUpdateLogs(): Collection
{
return $this->planUpdateLogs;
}
public function addPlanUpdateLog(PlanUpdateLog $planUpdateLog): self
{
if (!$this->planUpdateLogs->contains($planUpdateLog)) {
$this->planUpdateLogs[] = $planUpdateLog;
$planUpdateLog->setSubscription($this);
}
return $this;
}
public function removePlanUpdateLog(PlanUpdateLog $planUpdateLog): self
{
if ($this->planUpdateLogs->contains($planUpdateLog)) {
$this->planUpdateLogs->removeElement($planUpdateLog);
// set the owning side to null (unless already changed)
if ($planUpdateLog->getSubscription() === $this) {
$planUpdateLog->setSubscription(null);
}
}
return $this;
}
/**
* @return Collection|AbsenceLog[]
*/
public function getAbsenceLogs(): Collection
{
return $this->absenceLogs;
}
public function addAbsenceLog(AbsenceLog $absenceLog): self
{
if (!$this->absenceLogs->contains($absenceLog)) {
$this->absenceLogs[] = $absenceLog;
$absenceLog->setSubscription($this);
}
return $this;
}
public function removeAbsenceLog(AbsenceLog $absenceLog): self
{
if ($this->absenceLogs->contains($absenceLog)) {
$this->absenceLogs->removeElement($absenceLog);
// set the owning side to null (unless already changed)
if ($absenceLog->getSubscription() === $this) {
$absenceLog->setSubscription(null);
}
}
return $this;
}
/**
* @return Collection|SubscriptionLessonReport[]
*/
public function getSubscriptionLessonReports(): Collection
{
return $this->subscriptionLessonReports;
}
public function addSubscriptionLessonReport(SubscriptionLessonReport $subscriptionLessonReport): self
{
if (!$this->subscriptionLessonReports->contains($subscriptionLessonReport)) {
$this->subscriptionLessonReports[] = $subscriptionLessonReport;
$subscriptionLessonReport->setSubscription($this);
}
return $this;
}
public function removeSubscriptionLessonReport(SubscriptionLessonReport $subscriptionLessonReport): self
{
if ($this->subscriptionLessonReports->contains($subscriptionLessonReport)) {
$this->subscriptionLessonReports->removeElement($subscriptionLessonReport);
// set the owning side to null (unless already changed)
if ($subscriptionLessonReport->getSubscription() === $this) {
$subscriptionLessonReport->setSubscription(null);
}
}
return $this;
}
public function getCancellationDate(): ?\DateTimeInterface
{
return $this->cancellationDate;
}
public function setCancellationDate(?\DateTimeInterface $cancellationDate): self
{
$this->cancellationDate = $cancellationDate;
return $this;
}
public function __toString()
{
return $this->getCustomerId();
}
public function getSubjectLevel(): ?SubjectLevel
{
return $this->subjectLevel;
}
public function setSubjectLevel(?SubjectLevel $subjectLevel): self
{
$this->subjectLevel = $subjectLevel;
return $this;
}
public function getPaidAmount(): ?float
{
return $this->paidAmount;
}
public function setPaidAmount(float $paidAmount): self
{
$this->paidAmount = round($paidAmount, 2);
return $this;
}
public function getTotalLostMinutes(): ?int
{
return $this->TotalLostMinutes;
}
public function setTotalLostMinutes(?int $TotalLostMinutes): self
{
$this->TotalLostMinutes = $TotalLostMinutes;
return $this;
}
/**
* Quand des minutes de cours sont perdues, j'augmente le total avec les minutes perdues
* @param $lostMinutes
* @return mixed
*/
public function incrementTotalListMinutes($lostMinutes)
{
$newTotal = $this->TotalLostMinutes + $lostMinutes;
return $newTotal;
}
/**
* Quand des minutes sont rattrapées, je les déduit de ce total
* @param $minutesCaughtUp
* @return mixed
*/
public function decrementTotalListMinutes($minutesCaughtUp)
{
$newTotal = $this->TotalLostMinutes - $minutesCaughtUp;
return $newTotal;
}
/**
* @return Collection|Homework[]
*/
public function getHomeworks(): Collection
{
return $this->homeworks;
}
public function addHomework(Homework $homework): self
{
if (!$this->homeworks->contains($homework)) {
$this->homeworks[] = $homework;
$homework->setRelatedToSubscription($this);
}
return $this;
}
public function removeHomework(Homework $homework): self
{
if ($this->homeworks->contains($homework)) {
$this->homeworks->removeElement($homework);
// set the owning side to null (unless already changed)
if ($homework->getRelatedToSubscription() === $this) {
$homework->setRelatedToSubscription(null);
}
}
return $this;
}
public function getHaveRamadanCredit(): ?bool
{
return $this->haveRamadanCredit;
}
public function setHaveRamadanCredit(?bool $haveRamadanCredit): self
{
$this->haveRamadanCredit = $haveRamadanCredit;
return $this;
}
public function getRamadanCreditAmount(): ?float
{
return $this->ramadanCreditAmount;
}
public function setRamadanCreditAmount(?float $ramadanCreditAmount): self
{
$this->ramadanCreditAmount = round($ramadanCreditAmount, 2);
return $this;
}
/*
/**
* @Assert\Callback()
*/
/*
public function validate(ExecutionContextInterface $context, $payload) {
if($this->getSubject()->getHasLevel() === true) {
if( $this->getSubjectLevel() === null || $this->getSubjectLevel()->getSubject()->getId() != $this->getSubject()->getId() ) {
$context->buildViolation('form.subjectlevel.error')
->setTranslationDomain('subscription')
->atPath('subjectLevel')
->addViolation();
}
}
}*/
/**
* @return Collection|ActiveCampainSubscribeLostLog[]
*/
public function getSubscribeLostLogs(): Collection
{
return $this->subscribeLostLogs;
}
public function addSubscribeLostLog(ActiveCampainSubscribeLostLog $subscribeLostLog): self
{
if (!$this->subscribeLostLogs->contains($subscribeLostLog)) {
$this->subscribeLostLogs[] = $subscribeLostLog;
$subscribeLostLog->setSubscription($this);
}
return $this;
}
public function removeSubscribeLostLog(ActiveCampainSubscribeLostLog $subscribeLostLog): self
{
if ($this->subscribeLostLogs->removeElement($subscribeLostLog)) {
// set the owning side to null (unless already changed)
if ($subscribeLostLog->getSubscription() === $this) {
$subscribeLostLog->setSubscription(null);
}
}
return $this;
}
/**
* @return Collection|ActiveCampainUnsubscribeLog[]
*/
public function getUnsubscribeLogs(): Collection
{
return $this->unsubscribeLogs;
}
public function addUnsubscribeLog(ActiveCampainUnsubscribeLog $unsubscribeLog): self
{
if (!$this->unsubscribeLogs->contains($unsubscribeLog)) {
$this->unsubscribeLogs[] = $unsubscribeLog;
$unsubscribeLog->setSubscription($this);
}
return $this;
}
public function removeUnsubscribeLog(ActiveCampainUnsubscribeLog $unsubscribeLog): self
{
if ($this->unsubscribeLogs->removeElement($unsubscribeLog)) {
// set the owning side to null (unless already changed)
if ($unsubscribeLog->getSubscription() === $this) {
$unsubscribeLog->setSubscription(null);
}
}
return $this;
}
/**
* @return Collection|Exam[]
*/
public function getExams(): Collection
{
return $this->exams;
}
public function addExam(Exam $exam): self
{
if (!$this->exams->contains($exam)) {
$this->exams[] = $exam;
$exam->setRelatedToSubscription($this);
}
return $this;
}
public function removeExam(Exam $exam): self
{
if ($this->exams->removeElement($exam)) {
// set the owning side to null (unless already changed)
if ($exam->getRelatedToSubscription() === $this) {
$exam->setRelatedToSubscription(null);
}
}
return $this;
}
/**
* @return Collection|TrainingReport[]
*/
public function getTrainingReports(): Collection
{
return $this->trainingReports;
}
public function addTrainingReport(TrainingReport $trainingReport): self
{
if (!$this->trainingReports->contains($trainingReport)) {
$this->trainingReports[] = $trainingReport;
$trainingReport->setRelatedToSubscription($this);
}
return $this;
}
public function removeTrainingReport(TrainingReport $trainingReport): self
{
if ($this->trainingReports->removeElement($trainingReport)) {
// set the owning side to null (unless already changed)
if ($trainingReport->getRelatedToSubscription() === $this) {
$trainingReport->setRelatedToSubscription(null);
}
}
return $this;
}
}