<?phpnamespace JF\JuridicusBundle\Entity;use Doctrine\ORM\Mapping as ORM;/** * Rechnung */class Rechnung{ const CLASSNAME = __CLASS__; const TYP_GRUNDGEBUEHR = Gebuehr::TYP_GRUNDGEBUEHR; const TYP_WAHLFACHGEBUEHR = Gebuehr::TYP_WAHLFACHGEBUEHR; const TYP_STRAFGEBUEHR = Gebuehr::TYP_STRAFGEBUEHR; const TYP_ABOGEBUEHR = 4; /** * @var array */ private static $typen = array ( self::TYP_GRUNDGEBUEHR => 'Grundgebühr', self::TYP_WAHLFACHGEBUEHR => 'Wahlfachgebühr', self::TYP_STRAFGEBUEHR => 'Strafgeühr', self::TYP_ABOGEBUEHR => 'Abo-Gebühr', ); /** * * @return array */ public static function getTypOptions() { return self::$typen; } /** * @var integer */ private $id; /** * @var integer */ private $typ; /** * @var float */ private $betrag; /** * @var float */ private $bezahlt = 0.0; /** * @var \DateTime */ private $created_at; /** * @var \DateTime */ private $paid_at; /** * @var string */ private $nummer; /** * @var \JF\JuridicusBundle\Entity\KundePruefung */ private $buchung; /** * @var \JF\JuridicusBundle\Entity\Kunde */ private $kunde; /** * @var \JF\JuridicusBundle\Entity\AboZeitraum */ private $abo_zeitraum; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set typ * * @param integer $typ * @return Rechnung */ public function setTyp($typ) { $this->typ = $typ; return $this; } /** * Get typ * * @return integer */ public function getTyp() { return $this->typ; } /** * * @return string */ public function getTypString() { if (!isset(self::$typen[$this->typ])) { throw new \RuntimeException('Ungültiger Rechnungstyp'); } return self::$typen[$this->typ]; } /** * Set betrag * * @param float $betrag * @return Rechnung */ public function setBetrag($betrag) { $this->betrag = $betrag; return $this; } /** * Get betrag * * @return float */ public function getBetrag() { return $this->betrag; } /** * Set bezahlt * * @param float $bezahlt * @return Rechnung */ public function setBezahlt($bezahlt) { $this->bezahlt = $bezahlt; if ($this->bezahlt >= $this->betrag && $this->paid_at === null) { $this->paid_at = new \DateTime(); } else if ($this->bezahlt < $this->betrag && $this->paid_at !== null) { $this->paid_at = null; } return $this; } /** * Get bezahlt * * @return float */ public function getBezahlt() { return $this->bezahlt; } /** * Get offen * * @return float */ public function getOffen() { return $this->betrag - $this->bezahlt; } /** * * @return string */ public function getCssClass() { if ($this->paid_at) { return 'ok'; } else { $now = new \DateTime(); if ($now->diff($this->created_at)->days <= 28) { return 'ok'; } } return 'unpaid'; } /** * Set created_at * * @param \DateTime $createdAt * @return Rechnung */ public function setCreatedAt(\DateTime $createdAt = null) { $this->created_at = $createdAt; return $this; } /** * Get created_at * * @return \DateTime */ public function getCreatedAt() { return $this->created_at; } /** * Set buchung * * @param \JF\JuridicusBundle\Entity\KundePruefung $buchung * @return Rechnung */ public function setBuchung(KundePruefung $buchung = null) { $this->buchung = $buchung; return $this; } /** * Get buchung * * @return \JF\JuridicusBundle\Entity\KundePruefung */ public function getBuchung() { return $this->buchung; } /** * @ORM\PrePersist */ public function setCreatedAtValue() { if (!isset($this->created_at)) { $this->created_at = new \DateTime(); } } /** * Set paid_at * * @param \DateTime $paidAt * @return Rechnung */ public function setPaidAt(\DateTime $paidAt = null) { $this->paid_at = $paidAt; return $this; } /** * Get paid_at * * @return \DateTime */ public function getPaidAt() { return $this->paid_at; } /** * Set nummer * * @param string $nummer * @return Rechnung */ public function setNummer($nummer) { $this->nummer = $nummer; return $this; } /** * Get nummer * * @return string */ public function getNummer() { return $this->nummer; } /** * * @return string */ public function __toString() { return $this->nummer; } /** * Set kunde * * @param \JF\JuridicusBundle\Entity\Kunde $kunde * @return Rechnung */ 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 abo_zeitraum * * @param \JF\JuridicusBundle\Entity\AboZeitraum $aboZeitraum * @return Rechnung */ public function setAboZeitraum(AboZeitraum $aboZeitraum = null) { $this->abo_zeitraum = $aboZeitraum; return $this; } /** * Get abo_zeitraum * * @return \JF\JuridicusBundle\Entity\AboZeitraum */ public function getAboZeitraum() { return $this->abo_zeitraum; }}