src/JuridicusBundle/Entity/Rechnung.php line 10

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Rechnung
  6. */
  7. class Rechnung
  8. {
  9. const CLASSNAME = __CLASS__;
  10. const TYP_GRUNDGEBUEHR = Gebuehr::TYP_GRUNDGEBUEHR;
  11. const TYP_WAHLFACHGEBUEHR = Gebuehr::TYP_WAHLFACHGEBUEHR;
  12. const TYP_STRAFGEBUEHR = Gebuehr::TYP_STRAFGEBUEHR;
  13. const TYP_ABOGEBUEHR = 4;
  14. /**
  15. * @var array
  16. */
  17. private static $typen = array (
  18. self::TYP_GRUNDGEBUEHR => 'Grundgebühr',
  19. self::TYP_WAHLFACHGEBUEHR => 'Wahlfachgebühr',
  20. self::TYP_STRAFGEBUEHR => 'Strafgeühr',
  21. self::TYP_ABOGEBUEHR => 'Abo-Gebühr',
  22. );
  23. /**
  24. *
  25. * @return array
  26. */
  27. public static function getTypOptions()
  28. {
  29. return self::$typen;
  30. }
  31. /**
  32. * @var integer
  33. */
  34. private $id;
  35. /**
  36. * @var integer
  37. */
  38. private $typ;
  39. /**
  40. * @var float
  41. */
  42. private $betrag;
  43. /**
  44. * @var float
  45. */
  46. private $bezahlt = 0.0;
  47. /**
  48. * @var \DateTime
  49. */
  50. private $created_at;
  51. /**
  52. * @var \DateTime
  53. */
  54. private $paid_at;
  55. /**
  56. * @var string
  57. */
  58. private $nummer;
  59. /**
  60. * @var \JF\JuridicusBundle\Entity\KundePruefung
  61. */
  62. private $buchung;
  63. /**
  64. * @var \JF\JuridicusBundle\Entity\Kunde
  65. */
  66. private $kunde;
  67. /**
  68. * @var \JF\JuridicusBundle\Entity\AboZeitraum
  69. */
  70. private $abo_zeitraum;
  71. /**
  72. * Get id
  73. *
  74. * @return integer
  75. */
  76. public function getId()
  77. {
  78. return $this->id;
  79. }
  80. /**
  81. * Set typ
  82. *
  83. * @param integer $typ
  84. * @return Rechnung
  85. */
  86. public function setTyp($typ)
  87. {
  88. $this->typ = $typ;
  89. return $this;
  90. }
  91. /**
  92. * Get typ
  93. *
  94. * @return integer
  95. */
  96. public function getTyp()
  97. {
  98. return $this->typ;
  99. }
  100. /**
  101. *
  102. * @return string
  103. */
  104. public function getTypString()
  105. {
  106. if (!isset(self::$typen[$this->typ])) {
  107. throw new \RuntimeException('Ungültiger Rechnungstyp');
  108. }
  109. return self::$typen[$this->typ];
  110. }
  111. /**
  112. * Set betrag
  113. *
  114. * @param float $betrag
  115. * @return Rechnung
  116. */
  117. public function setBetrag($betrag)
  118. {
  119. $this->betrag = $betrag;
  120. return $this;
  121. }
  122. /**
  123. * Get betrag
  124. *
  125. * @return float
  126. */
  127. public function getBetrag()
  128. {
  129. return $this->betrag;
  130. }
  131. /**
  132. * Set bezahlt
  133. *
  134. * @param float $bezahlt
  135. * @return Rechnung
  136. */
  137. public function setBezahlt($bezahlt)
  138. {
  139. $this->bezahlt = $bezahlt;
  140. if ($this->bezahlt >= $this->betrag && $this->paid_at === null) {
  141. $this->paid_at = new \DateTime();
  142. } else if ($this->bezahlt < $this->betrag && $this->paid_at !== null) {
  143. $this->paid_at = null;
  144. }
  145. return $this;
  146. }
  147. /**
  148. * Get bezahlt
  149. *
  150. * @return float
  151. */
  152. public function getBezahlt()
  153. {
  154. return $this->bezahlt;
  155. }
  156. /**
  157. * Get offen
  158. *
  159. * @return float
  160. */
  161. public function getOffen()
  162. {
  163. return $this->betrag - $this->bezahlt;
  164. }
  165. /**
  166. *
  167. * @return string
  168. */
  169. public function getCssClass()
  170. {
  171. if ($this->paid_at) {
  172. return 'ok';
  173. } else {
  174. $now = new \DateTime();
  175. if ($now->diff($this->created_at)->days <= 28) {
  176. return 'ok';
  177. }
  178. }
  179. return 'unpaid';
  180. }
  181. /**
  182. * Set created_at
  183. *
  184. * @param \DateTime $createdAt
  185. * @return Rechnung
  186. */
  187. public function setCreatedAt(\DateTime $createdAt = null)
  188. {
  189. $this->created_at = $createdAt;
  190. return $this;
  191. }
  192. /**
  193. * Get created_at
  194. *
  195. * @return \DateTime
  196. */
  197. public function getCreatedAt()
  198. {
  199. return $this->created_at;
  200. }
  201. /**
  202. * Set buchung
  203. *
  204. * @param \JF\JuridicusBundle\Entity\KundePruefung $buchung
  205. * @return Rechnung
  206. */
  207. public function setBuchung(KundePruefung $buchung = null)
  208. {
  209. $this->buchung = $buchung;
  210. return $this;
  211. }
  212. /**
  213. * Get buchung
  214. *
  215. * @return \JF\JuridicusBundle\Entity\KundePruefung
  216. */
  217. public function getBuchung()
  218. {
  219. return $this->buchung;
  220. }
  221. /**
  222. * @ORM\PrePersist
  223. */
  224. public function setCreatedAtValue()
  225. {
  226. if (!isset($this->created_at)) {
  227. $this->created_at = new \DateTime();
  228. }
  229. }
  230. /**
  231. * Set paid_at
  232. *
  233. * @param \DateTime $paidAt
  234. * @return Rechnung
  235. */
  236. public function setPaidAt(\DateTime $paidAt = null)
  237. {
  238. $this->paid_at = $paidAt;
  239. return $this;
  240. }
  241. /**
  242. * Get paid_at
  243. *
  244. * @return \DateTime
  245. */
  246. public function getPaidAt()
  247. {
  248. return $this->paid_at;
  249. }
  250. /**
  251. * Set nummer
  252. *
  253. * @param string $nummer
  254. * @return Rechnung
  255. */
  256. public function setNummer($nummer)
  257. {
  258. $this->nummer = $nummer;
  259. return $this;
  260. }
  261. /**
  262. * Get nummer
  263. *
  264. * @return string
  265. */
  266. public function getNummer()
  267. {
  268. return $this->nummer;
  269. }
  270. /**
  271. *
  272. * @return string
  273. */
  274. public function __toString()
  275. {
  276. return $this->nummer;
  277. }
  278. /**
  279. * Set kunde
  280. *
  281. * @param \JF\JuridicusBundle\Entity\Kunde $kunde
  282. * @return Rechnung
  283. */
  284. public function setKunde(Kunde $kunde = null)
  285. {
  286. $this->kunde = $kunde;
  287. return $this;
  288. }
  289. /**
  290. * Get kunde
  291. *
  292. * @return \JF\JuridicusBundle\Entity\Kunde
  293. */
  294. public function getKunde()
  295. {
  296. return $this->kunde;
  297. }
  298. /**
  299. * Set abo_zeitraum
  300. *
  301. * @param \JF\JuridicusBundle\Entity\AboZeitraum $aboZeitraum
  302. * @return Rechnung
  303. */
  304. public function setAboZeitraum(AboZeitraum $aboZeitraum = null)
  305. {
  306. $this->abo_zeitraum = $aboZeitraum;
  307. return $this;
  308. }
  309. /**
  310. * Get abo_zeitraum
  311. *
  312. * @return \JF\JuridicusBundle\Entity\AboZeitraum
  313. */
  314. public function getAboZeitraum()
  315. {
  316. return $this->abo_zeitraum;
  317. }
  318. }