<?php
namespace JF\JuridicusBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* KundePruefung
* @UniqueEntity(fields={"kunde","pruefung"}, message="Diese Prüfung wurde bereits gebucht.")
* @UniqueEntity(fields={"kunde","datum_pruefung"}, message="An diesem Tag wurde bereits eine Prüfung gebucht.")
*/
class KundePruefung
{
const CLASSNAME = __CLASS__;
/**
* @var integer
*/
private $id;
/**
* @var \DateTime
* @Assert\Type(\DateTimeInterface::class)
*/
private $datum_pruefung;
/**
* @var \DateTime
* @Assert\Type(\DateTimeInterface::class)
*/
private $datum_buchung;
/**
* @var float
*/
private $betrag_gebuehr;
/**
* @var boolean
* @Assert\NotNull
*/
private $gebuehr_bezahlt = false;
/**
* @var float
*/
private $betrag_strafe;
/**
* @var boolean
* @Assert\NotNull
*/
private $strafe_bezahlt = false;
/**
* @var boolean
* @Assert\NotNull
*/
private $protokollpflicht = true;
/**
* @var boolean
* @Assert\NotNull
*/
private $klausurprotokollpflicht = true;
/**
* @var boolean
* @Assert\NotNull
*/
private $belohnung = false;
/**
* @var boolean
* @Assert\NotNull
*/
private $belohnung_bezahlt = false;
/**
* @var string
*/
private $notiz;
/**
* @var \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung
* @Assert\Valid
*/
private $protokoll_infothek_pruefung;
/**
* @var \JF\JuridicusBundle\Entity\Kunde
* @Assert\Valid
*/
private $kunde;
/**
* @var \JF\JuridicusBundle\Entity\Pruefung
* @Assert\Valid
*/
private $pruefung;
/**
* @var \JF\JuridicusBundle\Entity\Nachweis
* @Assert\Valid
*/
private $nachweis;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $emails;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $downloads;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $rechnungen;
/**
* @var \JF\JuridicusBundle\Entity\Gebuehr
* @Assert\Valid
*/
private $gebuehr;
/**
* @var \JF\JuridicusBundle\Entity\Gebuehr
* @Assert\Valid
*/
private $strafe;
/**
* @var \JF\JuridicusBundle\Entity\Pruefungsamt
* @Assert\NotNull
*/
private $pruefungsamt;
/**
* @var boolean
*/
private $abgemahnt = false;
/**
* @var \JF\JuridicusBundle\Entity\Gutschein
* @Assert\Valid
*/
private $gutschein;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $shoutbox_messages;
/**
* @var \JF\JuridicusBundle\Entity\ProtokollKlausur
*/
private $protokoll_klausur;
/**
*
* @var \JF\JuridicusBundle\Entity\ProtokollAktenvortrag
*/
private $protokoll_aktenvortrag;
/**
* @var boolean
*/
private $pflicht_facebook_post = false;
/**
* @var boolean
*/
private $wrote_facebook_post = false;
/**
* isInvalidGutschein
*
* @return boolean
*
* @Assert\IsFalse(groups={"gutschein"}, message = "Der Gutscheincode gilt nicht für Protokolle.")
* changedFrom Assert\False
*/
public function isInvalidGutschein()
{
$gutschein = $this->getGutschein();
if (!$gutschein || !$gutschein->getId()) {
return false;
}
return $gutschein->getValidZeitschrift() !== null;
}
/**
* Constructor
*/
public function __construct()
{
$this->emails = new \Doctrine\Common\Collections\ArrayCollection();
$this->downloads = new \Doctrine\Common\Collections\ArrayCollection();
$this->rechnungen = new \Doctrine\Common\Collections\ArrayCollection();
$this->shoutbox_messages = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set gebuehr_bezahlt
*
* @param boolean $gebuehrBezahlt
* @return KundePruefung
*/
public function setGebuehrBezahlt($gebuehrBezahlt)
{
$this->gebuehr_bezahlt = (bool) $gebuehrBezahlt;
return $this;
}
/**
* Get gebuehr_bezahlt
*
* @return boolean
*/
public function getGebuehrBezahlt()
{
return $this->gebuehr_bezahlt;
}
/**
* Set strafe_bezahlt
*
* @param boolean $strafeBezahlt
* @return KundePruefung
*/
public function setStrafeBezahlt($strafeBezahlt)
{
$this->strafe_bezahlt = (bool) $strafeBezahlt;
return $this;
}
/**
* Get strafe_bezahlt
*
* @return boolean
*/
public function getStrafeBezahlt()
{
return $this->strafe_bezahlt;
}
/**
* Set protokollpflicht
*
* @param boolean $protokollpflicht
* @return KundePruefung
*/
public function setProtokollpflicht($protokollpflicht)
{
$this->protokollpflicht = (bool) $protokollpflicht;
return $this;
}
/**
* Get protokollpflicht
*
* @return boolean
*/
public function getProtokollpflicht()
{
return $this->protokollpflicht;
}
/**
* Set protokoll_infothek_pruefung [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung $protokollInfothekPruefung
* @return KundePruefung
*/
public function setProtokollInfothekPruefung(ProtokollInfothekPruefung $protokollInfothekPruefung = null)
{
$this->protokoll_infothek_pruefung = $protokollInfothekPruefung;
return $this;
}
/**
* Get protokoll_infothek_pruefung
*
* @return \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung
*/
public function getProtokollInfothekPruefung()
{
return $this->protokoll_infothek_pruefung;
}
/**
* Set nachweis [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Nachweis $nachweis
* @return KundePruefung
*/
public function setNachweis(Nachweis $nachweis = null)
{
$this->nachweis = $nachweis;
return $this;
}
/**
* Get nachweis
*
* @return \JF\JuridicusBundle\Entity\Nachweis
*/
public function getNachweis()
{
return $this->nachweis;
}
/**
* Set kunde [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Kunde $kunde
* @return KundePruefung
*/
public function setKunde(Kunde $kunde = null)
{
$this->kunde = $kunde;
return $this;
}
/**
* Get kunde
*
* @return \JF\JuridicusBundle\Entity\Kunde
*/
public function getKunde()
{
return $this->kunde;
}
/**
* Set pruefung [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Pruefung $pruefung
* @return KundePruefung
*/
public function setPruefung(Pruefung $pruefung = null)
{
$this->pruefung = $pruefung;
return $this;
}
/**
* Get pruefung
*
* @return \JF\JuridicusBundle\Entity\Pruefung
*/
public function getPruefung()
{
return $this->pruefung;
}
/**
* Set datum_pruefung
*
* @param \DateTime $datumPruefung
* @return KundePruefung
*/
public function setDatumPruefung(\DateTime $datumPruefung)
{
if ($datumPruefung != $this->datum_pruefung) {
$this->datum_pruefung = $datumPruefung;
if ($this->pruefung) {
$this->pruefung->setDatum($datumPruefung);
}
}
return $this;
}
/**
* Get datum_pruefung
*
* @return \DateTime
*/
public function getDatumPruefung()
{
return $this->datum_pruefung;
}
/**
* Set datum_buchung
*
* @param \DateTime $datumBuchung
* @return KundePruefung
*/
public function setDatumBuchung(\DateTime $datumBuchung = null)
{
$this->datum_buchung = $datumBuchung;
return $this;
}
/**
* Get datum_buchung
*
* @return \DateTime
*/
public function getDatumBuchung()
{
return $this->datum_buchung;
}
/**
* Get days since buchungsdatum
*
* @return integer | null
*/
public function getDaysSinceBuchungsdatum()
{
if (!$this->datum_buchung) {
return null;
}
$now = new \DateTime();
return $this->datum_buchung->diff($now)->format('%r%a');
}
/**
* Get days since pruefungsdatum
*
* @return integer
*/
public function getDaysSincePruefungsdatum()
{
$now = new \DateTime();
return $this->datum_pruefung->diff($now)->format('%r%a');
}
/**
* Kunden, die nach 4 Wochen kein Protokoll geschrieben und nicht bezahlt haben, erhalten die CSS-Klass unpaid
* @return string css class
*/
public function getCssClass()
{
// keine Protokollpflicht => ok
if ($this->protokollpflicht === false) {
return 'ok';
} else if ($this->getBetragGebuehr() && ! $this->gebuehr_bezahlt && $this->getDaysSinceBuchungsdatum() > 28) {
// 28 Tage nach Buchung keine Gebühr bezahlt => unpaid
return 'unpaid';
} else if ($this->getBetragStrafe() && ! $this->strafe_bezahlt && $this->getDaysSincePruefungsdatum() > 28) {
// 28 Tage nach Prüfung keine Strafe bezahlt => Protokoll untersuchen
return $this->isProtokollFertig() ? 'ok' : 'unpaid';
}
return 'ok';
}
/**
*
* String Representation
*
* @return string
*/
public function __toString()
{
if (isset($this->id))
{
return sprintf('Buchung #%s - %s - %s',
$this->getId(), $this->getDatumPruefung()->format('d.m.Y'), $this->getKunde()->getEmail()
);
}
return 'Neue Buchung';
}
/**
* Set Notiz
*
* @param string $notiz
* @return KundePruefung
*/
public function setNotiz($notiz)
{
$this->notiz = $notiz;
return $this;
}
/**
* Get notiz
*
* @return string
*/
public function getNotiz()
{
return $this->notiz;
}
/**
* Add email
*
* @param \JF\JuridicusBundle\Entity\Email $email
* @return KundePruefung
*/
public function addEmail(Email $email)
{
$this->emails[] = $email;
return $this;
}
/**
* Remove email
*
* @param \JF\JuridicusBundle\Entity\Email $email
*/
public function removeEmail(Email $email)
{
$this->emails->removeElement($email);
}
/**
* Get emails
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getEmails()
{
return $this->emails;
}
/**
*
* @param integer $typ
* @return JF\JuridicusBundle\Entity\Email|null
*/
public function getEmail($typ)
{
foreach ($this->getEmails() as $email) {
/* @var $email \JF\JuridicusBundle\Entity\Email */
if ($email->getTyp() == $typ) {
return $email;
}
}
return null;
}
/**
*
* @return Email|null
*/
public function getEmailRechnung()
{
$email_rechnung = $this->getEmail(Email::BUCHUNG_RECHNUNG);
if ($email_rechnung) {
return $email_rechnung;
}
$email_rechnung = $this->getEmail(Email::BUCHUNG_RECHNUNG_NACHTRAG);
if ($email_rechnung) {
return $email_rechnung;
}
return null;
}
/**
*
* @return string|null
*/
public function getEndnote()
{
$protokoll_infothek_pruefung = $this->getProtokollInfothekPruefung();
if (! $protokoll_infothek_pruefung) {
return null;
}
return $protokoll_infothek_pruefung->getProtokollInfothekNoten()->first()->getEndnote();
}
/**
*
* @return string|null
*/
public function getEndnote1()
{
$protokoll_infothek_pruefung = $this->getProtokollInfothekPruefung();
if (! $protokoll_infothek_pruefung) {
return null;
}
return $protokoll_infothek_pruefung->getProtokollInfothekNoten()->first()->getEndnote1();
}
/**
* Set gebuehr [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Gebuehr $gebuehr
* @return KundePruefung
*/
public function setGebuehr(Gebuehr $gebuehr = null)
{
$this->gebuehr = $gebuehr;
return $this;
}
/**
* Get gebuehr
*
* @return \JF\JuridicusBundle\Entity\Gebuehr
*/
public function getGebuehr()
{
return $this->gebuehr;
}
/**
* Set strafe [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Gebuehr $strafe
* @return KundePruefung
*/
public function setStrafe(Gebuehr $strafe = null)
{
$this->strafe = $strafe;
return $this;
}
/**
* Get strafe
*
* @return \JF\JuridicusBundle\Entity\Gebuehr
*/
public function getStrafe()
{
return $this->strafe;
}
/**
* Set pruefungsamt [OWNING SIDE]
*
* @param \JF\JuridicusBundle\Entity\Pruefungsamt $pruefungsamt
* @return KundePruefung
*/
public function setPruefungsamt(Pruefungsamt $pruefungsamt = null)
{
$this->pruefungsamt = $pruefungsamt;
return $this;
}
/**
* Get pruefungsamt
*
* @return \JF\JuridicusBundle\Entity\Pruefungsamt
*/
public function getPruefungsamt()
{
return $this->pruefungsamt;
}
/**
* Set abgemahnt
*
* @param boolean $abgemahnt
* @return KundePruefung
*/
public function setAbgemahnt($abgemahnt)
{
$this->abgemahnt = (bool) $abgemahnt;
return $this;
}
/**
* Get abgemahnt
*
* @return boolean
*/
public function getAbgemahnt()
{
return $this->abgemahnt;
}
/**
* Add download
*
* @param \JF\JuridicusBundle\Entity\Download $download
* @return KundePruefung
*/
public function addDownload(Download $download)
{
$this->downloads[] = $download;
return $this;
}
/**
* Remove download
*
* @param \JF\JuridicusBundle\Entity\Download $downloads
*/
public function removeDownload(Download $download)
{
$this->downloads->removeElement($download);
}
/**
* Get downloads
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getDownloads()
{
return $this->downloads;
}
/**
* Set belohnung
*
* @param boolean $belohnung
* @return KundePruefung
*/
public function setBelohnung($belohnung)
{
$this->belohnung = (bool) $belohnung;
return $this;
}
/**
* Get belohnung
*
* @return boolean
*/
public function getBelohnung()
{
return $this->belohnung;
}
/**
* Set belohnung_bezahlt
*
* @param boolean $belohnungBezahlt
* @return KundePruefung
*/
public function setBelohnungBezahlt($belohnungBezahlt)
{
$this->belohnung_bezahlt = (bool) $belohnungBezahlt;
return $this;
}
/**
* Get belohnung_bezahlt
*
* @return boolean
*/
public function getBelohnungBezahlt()
{
return $this->belohnung_bezahlt;
}
/**
* Set gutschein
*
* @param \JF\JuridicusBundle\Entity\Gutschein $gutschein
* @return KundePruefung
*/
public function setGutschein(Gutschein $gutschein = null)
{
$this->gutschein = $gutschein;
return $this;
}
/**
* Get gutschein
*
* @return \JF\JuridicusBundle\Entity\Gutschein
*/
public function getGutschein()
{
return $this->gutschein;
}
/**
* Set betrag_gebuehr
*
* @param float $betragGebuehr
* @return KundePruefung
*/
public function setBetragGebuehr($betragGebuehr)
{
$this->betrag_gebuehr = $betragGebuehr;
return $this;
}
/**
* Get betrag_gebuehr
*
* @return float
*/
public function getBetragGebuehr()
{
return $this->betrag_gebuehr;
}
/**
* Set betrag_strafe
*
* @param float $betragStrafe
* @return KundePruefung
*/
public function setBetragStrafe($betragStrafe)
{
$this->betrag_strafe = $betragStrafe;
return $this;
}
/**
* Get betrag_strafe
*
* @return float
*/
public function getBetragStrafe()
{
return $this->betrag_strafe;
}
/**
* Add rechnung
*
* @param \JF\JuridicusBundle\Entity\Rechnung $rechnung
* @return KundePruefung
*/
public function addRechnungen(Rechnung $rechnung)
{
$this->rechnungen[] = $rechnung;
$rechnung->setBuchung($this);
return $this;
}
/**
* Remove rechnung
*
* @param \JF\JuridicusBundle\Entity\Rechnung $rechnung
*/
public function removeRechnungen(Rechnung $rechnung)
{
$this->rechnungen->removeElement($rechnung);
$rechnung->setBuchung(null);
}
/**
* Get rechnungen
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRechnungen()
{
return $this->rechnungen;
}
/**
*
* @param integer $gebuehr_typ
* @return Rechnung | null
*/
public function getRechnung($gebuehr_typ)
{
foreach ($this->getRechnungen() as $rechnung) {
/* @var $rechnung \JF\JuridicusBundle\Entity\Rechnung */
if ($rechnung->getTyp() == $gebuehr_typ) {
return $rechnung;
}
}
return null;
}
/**
*
* @return boolean
*/
public function isProtokollFertig()
{
$protokoll = $this->getProtokollInfothekPruefung();
return $protokoll && $protokoll->getFertig();
}
/**
* Add shoutbox_messages
*
* @param \JF\JuridicusBundle\Entity\ShoutboxMessage $shoutboxMessage
* @return KundePruefung
*/
public function addShoutboxMessage(ShoutboxMessage $shoutboxMessage)
{
$this->shoutbox_messages[] = $shoutboxMessage;
$shoutboxMessage->setBuchung($this);
return $this;
}
/**
* Remove shoutbox_messages
*
* @param \JF\JuridicusBundle\Entity\ShoutboxMessage $shoutboxMessage
*/
public function removeShoutboxMessage(ShoutboxMessage $shoutboxMessage)
{
$this->shoutbox_messages->removeElement($shoutboxMessage);
$shoutboxMessage->setBuchung(null);
}
/**
* Get shoutbox_messages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getShoutboxMessages()
{
return $this->shoutbox_messages;
}
/**
* Set klausurprotokollpflicht
*
* @param boolean $klausurprotokollpflicht
* @return Kunde
*/
public function setKlausurprotokollpflicht($klausurprotokollpflicht = true)
{
$this->klausurprotokollpflicht = (bool) $klausurprotokollpflicht;
return $this;
}
/**
* Get klausurprotokollpflicht
*
* @return boolean
*/
public function getKlausurprotokollpflicht()
{
return $this->klausurprotokollpflicht;
}
/**
* Set protokoll_klausur
*
* @param \JF\JuridicusBundle\Entity\ProtokollKlausur $protokollKlausur
* @return Kunde
*/
public function setProtokollKlausur(ProtokollKlausur $protokollKlausur = null)
{
$this->protokoll_klausur = $protokollKlausur;
if ($protokollKlausur) {
$protokollKlausur->setKundePruefung($this);
}
return $this;
}
/**
* Get protokoll_klausur
*
* @return \JF\JuridicusBundle\Entity\ProtokollKlausur
*/
public function getProtokollKlausur()
{
return $this->protokoll_klausur;
}
/**
* Set protokoll_aktenvortrag
*
* @param \JF\JuridicusBundle\Entity\ProtokollAktenvortrag $protokollAktenvortrag
* @return Kunde
*/
public function setProtokollAktenvortrag(ProtokollAktenvortrag $protokollAktenvortrag = null)
{
$this->protokoll_aktenvortrag = $protokollAktenvortrag;
if ($protokollAktenvortrag) {
$protokollAktenvortrag->setKundePruefung($this);
}
return $this;
}
/**
* Get protokoll_aktenvortrag
*
* @return \JF\JuridicusBundle\Entity\ProtokollAktenvortrag
*/
public function getProtokollAktenvortrag()
{
return $this->protokoll_aktenvortrag;
}
/**
*
* @return boolean
*/
public function needsKlausurprotokoll()
{
if ($this->getKlausurprotokollpflicht()) {
$protokoll_klausur = $this->getProtokollKlausur();
if (!$protokoll_klausur || !$protokoll_klausur->isFertig()) {
return true;
}
}
return false;
}
/**
* Set pflicht_facebook_post
*
* @param boolean $pflichtFacebookPost
* @return KundePruefung
*/
public function setPflichtFacebookPost($pflichtFacebookPost)
{
$this->pflicht_facebook_post = (bool) $pflichtFacebookPost;
return $this;
}
/**
* Get pflicht_facebook_post
*
* @return boolean
*/
public function getPflichtFacebookPost()
{
return $this->pflicht_facebook_post;
}
/**
* Set wrote_facebook_post
*
* @param boolean $wroteFacebookPost
* @return KundePruefung
*/
public function setWroteFacebookPost($wroteFacebookPost)
{
$this->wrote_facebook_post = (bool) $wroteFacebookPost;
return $this;
}
/**
* Get wrote_facebook_post
*
* @return boolean
*/
public function getWroteFacebookPost()
{
return $this->wrote_facebook_post;
}
/**
*
* @return boolean
*/
public function needsFacebookPost()
{
return $this->pflicht_facebook_post && !$this->wrote_facebook_post;
}
}