src/JuridicusBundle/Services/PdfCreator.php line 38

Open in your IDE?
  1. <?php
  2. namespace JF\JuridicusBundle\Services;
  3. use Doctrine\ORM\EntityManager;
  4. //use Symfony\Component\HttpKernel\Log\LoggerInterface;
  5. use Symfony\Component\Process\Process;
  6. use Symfony\Component\Process\ProcessBuilder;
  7. use JF\JuridicusBundle\Entity\Kunde;
  8. use JF\JuridicusBundle\Entity\Pruefer;
  9. use JF\JuridicusBundle\Entity\KundePruefung;
  10. use JF\JuridicusBundle\Entity\Rechnung;
  11. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefer;
  12. use JF\JuridicusBundle\Entity\ProtokollInfothekPruefung;
  13. use JF\JuridicusBundle\Entity\PdfStempel;
  14. use JF\JuridicusBundle\Entity\PdfProtokollmappePruefer;
  15. use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer;
  16. use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefung;
  17. use JF\JuridicusBundle\Entity\AboZeitraum;
  18. use JF\JuridicusBundle\Entity\Abo;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Psr\Log\LoggerInterface;
  21. use WhiteOctober\TCPDFBundle\Controller\TCPDFController;
  22. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  23. class PdfCreator
  24. {
  25. private EntityManagerInterface $em;
  26. private LoggerInterface $logger;
  27. private TCPDFController $tcpdfController;
  28. private array $params;
  29. public function __construct(
  30. EntityManagerInterface $em,
  31. LoggerInterface $logger,
  32. ParameterBagInterface $bag
  33. ) {
  34. $this->em = $em;
  35. $this->logger = $logger;
  36. $this->tcpdf = new TCPDFController('TCPDF'); // direkt instanziiert
  37. $projectDir = $bag->get('kernel.project_dir');
  38. $this->params = [
  39. 'pdf_creator' => 'Juridicus GmbH',
  40. 'k_path_images' => $projectDir.'/../src/JF/JuridicusBundle/Resources/public/images/',
  41. 'pdf_author' => 'Juridicus GmbH',
  42. 'pdf_page_format' => 'A4',
  43. 'pdf_page_orientation' => 'P',
  44. 'pdf_header_logo' => 'juridicus.png',
  45. 'pdf_unit' => 'mm',
  46. 'pdf_header_logo_width' => '30',
  47. 'pdf_margin_header' => '10',
  48. 'pdf_font_size_main' => '10',
  49. 'pdf_font_size_data' => '8',
  50. 'pdf_font_monospaced' => 'courier',
  51. 'pdf_margin_left' => '15',
  52. 'pdf_margin_right' => '15',
  53. 'pdf_margin_top' => '27',
  54. 'pdf_margin_footer' => '10',
  55. 'pdf_margin_bottom' => '25',
  56. 'pdf_image_scale_ratio' => '1',
  57. 'pdf_font_name_main' => 'dejavusans',
  58. 'pdf_font_name_data' => 'dejavusans'
  59. ];
  60. }
  61. /**
  62. * Language definitions for TCPDF configuration
  63. *
  64. * @var array
  65. */
  66. protected static $tcpdf_language = array(
  67. 'a_meta_charset' => 'UTF-8',
  68. 'a_meta_dir' => 'ltr',
  69. 'a_meta_language' => 'de',
  70. 'w_page' => 'Seite'
  71. );
  72. public function setEntityManager(EntityManager $em)
  73. {
  74. $this->em = $em;
  75. return $this;
  76. }
  77. public function setLogger(LoggerInterface $logger)
  78. {
  79. $this->logger = $logger;
  80. return $this;
  81. }
  82. public function setTcpdf(TCPDFController $tcpdf)
  83. {
  84. $this->tcpdf = $tcpdf;
  85. return $this;
  86. }
  87. /**
  88. *
  89. * @param array $params
  90. * @return \JF\JuridicusBundle\Services\PdfCreator
  91. */
  92. public function setParameters(array $params)
  93. {
  94. $this->params = $params;
  95. return $this;
  96. }
  97. /**
  98. * erstellt einen Stempel
  99. *
  100. * @param \JF\JuridicusBundle\Entity\Kunde
  101. * @return \JF\JuridicusBundle\Entity\PdfStempel | null
  102. */
  103. public function createStempel(Kunde $kunde)
  104. {
  105. $tcpdf = $this->tcpdf->create();
  106. $params = $this->params;
  107. // TCPDF konfigurieren
  108. $tcpdf->SetMargins(25, 1); // $params['pdf_margin_right'] - 15
  109. $tcpdf->SetPrintHeader(false);
  110. $tcpdf->SetPrintFooter(false);
  111. $tcpdf->SetFont('dejavusans', '', 6);
  112. $tcpdf->AddPage();
  113. // alten Stempel finden
  114. $pdf_stempel = $kunde->getPdfStempel();
  115. if (null === $pdf_stempel) {
  116. $pdf_stempel = new PdfStempel();
  117. $pdf_stempel->setKunde($kunde);
  118. }
  119. $kunde->addToPdf($tcpdf);
  120. // auf Platte speichern
  121. $stempel_dir = $pdf_stempel->getDir();
  122. $path = tempnam($stempel_dir, "stempel_");
  123. chmod($path, 0666);
  124. $tcpdf->Output($path, 'F');
  125. // Entity vervollständigen und speichern
  126. $pdf_stempel
  127. ->setMimeType('application/pdf')
  128. ->setPath($path)
  129. ->setSize(filesize($path))
  130. ;
  131. $this->em->persist($pdf_stempel);
  132. return $pdf_stempel;
  133. }
  134. /**
  135. * erstellt ein Prüfungsprotokoll für alle Prüfer
  136. *
  137. * @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung
  138. * @return \JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefung | null
  139. */
  140. public function createProtokollPruefung(ProtokollInfothekPruefung $protokoll_infothek_pruefung)
  141. {
  142. // altes Protokoll suchen
  143. $pdf = $protokoll_infothek_pruefung->getPdfProtokollInfothekPruefung();
  144. if (!$pdf) {
  145. // neues Protokoll erstellen
  146. $pdf = new PdfProtokollInfothekPruefung();
  147. $pdf->setProtokollInfothekPruefung($protokoll_infothek_pruefung);
  148. }
  149. $tcpdf = $this->tcpdf->create();
  150. $params = $this->params;
  151. $title_string = sprintf('Juridicus - Protokoll #%d - %s', $protokoll_infothek_pruefung->getId(), $protokoll_infothek_pruefung->getDatum()->format('d.m.Y')
  152. );
  153. // TCPDF konfigurieren
  154. $tcpdf->SetCreator($params['pdf_creator']);
  155. $tcpdf->SetAuthor($params['pdf_author']);
  156. $tcpdf->SetTitle($title_string);
  157. $tcpdf->SetSubject($title_string);
  158. $tcpdf->SetKeywords('Juridicus');
  159. $tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
  160. $tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
  161. $tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
  162. $tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
  163. $tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
  164. $tcpdf->SetHeaderMargin($params['pdf_margin_header']);
  165. $tcpdf->SetFooterMargin($params['pdf_margin_footer']);
  166. $tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
  167. $tcpdf->setImageScale($params['pdf_image_scale_ratio']);
  168. $tcpdf->setLanguageArray(self::$tcpdf_language);
  169. $tcpdf->SetFont('dejavusans', '', 10);
  170. foreach ($protokoll_infothek_pruefung->getProtokollInfothekPruefer() as $protokoll_infothek_pruefer) {
  171. $pruefer_string = $protokoll_infothek_pruefer->getPruefer()->getFullText();
  172. $tcpdf->AddPage();
  173. $tcpdf->Bookmark($pruefer_string, 0, 0);
  174. $tcpdf->Cell(0, 10, $pruefer_string, 0, 1, 'L');
  175. $protokoll_infothek_pruefer->addToPdf($tcpdf);
  176. }
  177. // add a new page for TOC
  178. $tcpdf->AddPage();
  179. // write the TOC title
  180. $tcpdf->SetFont('dejavusans', 'B', 16);
  181. $tcpdf->MultiCell(0, 0, 'Inhaltsverzeichnis', 0, 'C');
  182. $tcpdf->Ln();
  183. // add table of content at page 1
  184. $tcpdf->SetFont('dejavusans', '', 12);
  185. $tcpdf->addTOC(1, 'dejavusans', '.', $title_string);
  186. // auf Platte speichern
  187. $dir = $pdf->getDir();
  188. $path = tempnam($dir, $protokoll_infothek_pruefung->getId());
  189. chmod($path, 0666);
  190. $tcpdf->Output($path, 'F');
  191. // Entity vervollständigen und speichern
  192. $pdf
  193. ->setMimeType('application/pdf')
  194. ->setPath($path)
  195. ->setSize(filesize($path))
  196. ;
  197. $this->em->persist($pdf);
  198. return $pdf;
  199. }
  200. /**
  201. * erstellt ein Prüfungsprotokoll für einen einzelnen Prüfer
  202. *
  203. * @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefer
  204. * @return \JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer | null
  205. */
  206. public function createProtokollPruefer(ProtokollInfothekPruefer $protokoll_infothek_pruefer)
  207. {
  208. // altes Protokoll vorhanden?
  209. $pdf = $protokoll_infothek_pruefer->getPdfProtokollInfothekPruefer();
  210. if (!$pdf) {
  211. // neues Pdf erstellen
  212. $pdf = new PdfProtokollInfothekPruefer();
  213. $pdf->setProtokollInfothekPruefer($protokoll_infothek_pruefer);
  214. }
  215. $tcpdf = $this->tcpdf->create();
  216. $params = $this->params;
  217. // TCPDF konfigurieren
  218. $protokoll_infothek_pruefung = $protokoll_infothek_pruefer->getProtokollInfothekPruefung();
  219. $pruefer_string = $protokoll_infothek_pruefer->getPruefer()->getFullText();
  220. $datum_string = $protokoll_infothek_pruefung->getDatum()->format('d.m.Y');
  221. $title_string = sprintf('Juridicus - Neues Protokoll %s', $pruefer_string);
  222. $tcpdf->SetCreator($params['pdf_creator']);
  223. $tcpdf->SetAuthor($params['pdf_author']);
  224. $tcpdf->SetTitle($title_string);
  225. $tcpdf->SetSubject($title_string);
  226. $tcpdf->SetKeywords('Juridicus', $pruefer_string);
  227. $tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
  228. $tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
  229. $tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
  230. $tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
  231. $tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
  232. $tcpdf->SetHeaderMargin($params['pdf_margin_header']);
  233. $tcpdf->SetFooterMargin($params['pdf_margin_footer']);
  234. $tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
  235. $tcpdf->setImageScale($params['pdf_image_scale_ratio']);
  236. $tcpdf->setLanguageArray(self::$tcpdf_language);
  237. $tcpdf->SetFont('dejavusans', '', 10);
  238. $tcpdf->AddPage();
  239. $tcpdf->Cell(0, 10, sprintf('Protokoll - %s - %s', $pruefer_string, $datum_string), 0, 1, 'L');
  240. $protokoll_infothek_pruefer->addToPdf($tcpdf);
  241. // auf Platte speichern
  242. $dir = $pdf->getDir();
  243. $path = tempnam($dir, $protokoll_infothek_pruefer->getId());
  244. chmod($path, 0666);
  245. $tcpdf->Output($path, 'F');
  246. // Entity vervollständigen und speichern
  247. $pdf
  248. ->setMimeType('application/pdf')
  249. ->setPath($path)
  250. ->setSize(filesize($path))
  251. ;
  252. $this->em->persist($pdf);
  253. return $pdf;
  254. }
  255. /**
  256. * erstellt eine Protokollmappe
  257. *
  258. * @param \JF\JuridicusBundle\Pruefer $pruefer
  259. * @integer $examen
  260. * @return \JF\JuridicusBundle\PdfProtokollmappePruefer|null
  261. */
  262. public function createProtokollmappePruefer(Pruefer $pruefer, $examen)
  263. {
  264. $anzahl_protokolle = 0;
  265. // html-Protokolle holen
  266. $html_protokolle = $this->em->getRepository('JFJuridicusBundle:ProtokollHtml')->findByPrueferAndExamen($pruefer, $examen);
  267. $anzahl_html_protokolle = count($html_protokolle);
  268. $anzahl_protokolle += $anzahl_html_protokolle;
  269. echo "Anzahl HTML Protokolle: ", $anzahl_html_protokolle, PHP_EOL;
  270. // Infothek-Protokolle holen
  271. $infothek_protokolle = $this->em->getRepository('JFJuridicusBundle:ProtokollInfothekPruefer')
  272. ->findByPrueferAndExamen($pruefer, $examen);
  273. $anzahl_infothek_protokolle = count($infothek_protokolle);
  274. $anzahl_protokolle += $anzahl_infothek_protokolle;
  275. echo "Anzahl Infothek Protokolle: ", $anzahl_infothek_protokolle, PHP_EOL;
  276. // Juridicus-Protokolle holen
  277. $juridicus_protokolle = $this->em->getRepository('JFJuridicusBundle:PdfProtokollJuridicus')
  278. ->findByPrueferAndExamen($pruefer, $examen);
  279. $anzahl_juridicus_protokolle = 0;
  280. foreach ($juridicus_protokolle as $juridicus_protokoll) {
  281. $anzahl_juridicus_protokolle += $juridicus_protokoll->getAnzahlProtokolle();
  282. }
  283. $anzahl_protokolle += $anzahl_juridicus_protokolle;
  284. echo "Anzahl Juridicus-Protokolle: ", $anzahl_juridicus_protokolle, PHP_EOL;
  285. // alte Protokollmappe holen
  286. $pdf = $this->em->getRepository('JFJuridicusBundle:PdfProtokollmappePruefer')->findOneBy(array(
  287. 'pruefer' => $pruefer->getId(), 'examen' => $examen
  288. ));
  289. if ($anzahl_protokolle == 0) {
  290. if ($pdf) {
  291. // alte Protokollmappe löschen
  292. $this->em->remove($pdf);
  293. }
  294. return null;
  295. }
  296. // neue Protokollmappe erstellen?
  297. if (!$pdf) {
  298. $pdf = new PdfProtokollmappePruefer();
  299. $pdf->setPruefer($pruefer)->setExamen($examen);
  300. }
  301. // TCPDF konfigurieren
  302. $tcpdf = $this->tcpdf->create();
  303. $params = $this->params;
  304. $pruefer_string = $pruefer->getFullText();
  305. $title_string = sprintf('Juridicus - %s', $pruefer_string);
  306. $tcpdf->SetCreator($params['pdf_creator']);
  307. $tcpdf->SetAuthor($params['pdf_author']);
  308. $tcpdf->SetTitle($title_string);
  309. $tcpdf->SetSubject($title_string);
  310. $tcpdf->SetKeywords('Juridicus', $pruefer_string);
  311. $tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
  312. $tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
  313. $tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
  314. $tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
  315. $tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
  316. $tcpdf->SetHeaderMargin($params['pdf_margin_header']);
  317. $tcpdf->SetFooterMargin($params['pdf_margin_footer']);
  318. $tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
  319. $tcpdf->setImageScale($params['pdf_image_scale_ratio']);
  320. $tcpdf->setLanguageArray(self::$tcpdf_language);
  321. $tcpdf->SetFont('dejavusans', '', 10);
  322. // Statistik hinzufügen
  323. $statistik = $this->em->getRepository('JFJuridicusBundle:ProtokollInfothekPruefer')->filterParagraphsByPruefer($pruefer,$examen);
  324. $this->addStatistik($tcpdf, $statistik);
  325. $j = 0;
  326. // erste Protokolle der beiden Listen holen
  327. $infothek_protokoll = array_shift($infothek_protokolle);
  328. if ($infothek_protokoll) {
  329. $infothek_datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
  330. }
  331. $html_protokoll = array_shift($html_protokolle);
  332. if ($html_protokoll) {
  333. $html_datum = $html_protokoll->getDatum();
  334. }
  335. while ($infothek_protokoll || $html_protokoll) {
  336. // welches Protokoll ist das nächste?
  337. if ($infothek_protokoll && $html_protokoll) {
  338. $protokoll_select = ($html_datum === null || $html_datum < $infothek_datum) ? 'infothek' : 'html';
  339. } elseif ($infothek_protokoll) {
  340. $protokoll_select = 'infothek';
  341. } elseif ($html_protokoll) {
  342. $protokoll_select = 'html';
  343. }
  344. if ($protokoll_select === 'infothek') {
  345. $datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
  346. $protokoll = $infothek_protokoll;
  347. // hole nächstes Infohek-Protokoll
  348. $infothek_protokoll = array_shift($infothek_protokolle);
  349. if ($infothek_protokoll) {
  350. $infothek_datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
  351. }
  352. } else {
  353. $datum = $html_protokoll->getDatum();
  354. $protokoll = $html_protokoll;
  355. // hole nächstes HTML-Protokoll
  356. $html_protokoll = array_shift($html_protokolle);
  357. if ($html_protokoll) {
  358. $html_datum = $html_protokoll->getDatum();
  359. }
  360. }
  361. $j++;
  362. if ($datum) {
  363. $title_string = sprintf('Protokoll %d - %s', $j, $datum->format('d.m.Y'));
  364. } else {
  365. $title_string = sprintf('Protokoll %d', $j);
  366. }
  367. $tcpdf->AddPage();
  368. $tcpdf->Bookmark($title_string, 0, 0);
  369. $tcpdf->Cell(0, 10, $title_string, 0, 1, 'L');
  370. $protokoll->addToPdf($tcpdf);
  371. }
  372. // Link auf Anhang, falls nicht alle Protokolle im Inhaltsverzeichnis auftauchen
  373. if ($j > 0 && $anzahl_juridicus_protokolle > 0) {
  374. $tcpdf->AddPage();
  375. $tcpdf->Bookmark('Anhang', 0, 0);
  376. $tcpdf->Ln(25);
  377. $tcpdf->SetFont('dejavusans', 'B', 20);
  378. $tcpdf->Cell(0, 0, 'Anhang', 0, 1, 'C');
  379. $tcpdf->SetFont('dejavusans', '', 12);
  380. $tcpdf->Cell(0, 0, '(Protokolle aus dem Zusammenschluss)', 0, 1, 'C');
  381. }
  382. // add a new page for TOC
  383. $title_string = sprintf('Protokollmappe %s. Staatsexamen', $examen);
  384. $tcpdf->AddPage();
  385. // write the TOC title
  386. $tcpdf->SetFont('dejavusans', 'B', 16);
  387. $tcpdf->Cell(0, 0, $title_string, 0, 1, 'C');
  388. $tcpdf->Ln(5);
  389. $tcpdf->SetFont('dejavusans', '', 12);
  390. // add table of content at page 1
  391. $tcpdf->addTOC(1, 'dejavusans', '.', $pruefer_string);
  392. // auf Platte speichern
  393. $dir = $pdf->getDir();
  394. $path = tempnam($dir, "protokollmappe_");
  395. chmod($path, 0666);
  396. $tcpdf->Output($path, 'F');
  397. // Juridicus Protokolle mergen
  398. if ($anzahl_juridicus_protokolle > 0) {
  399. /**
  400. * @todo restore bookmarks
  401. */
  402. /*
  403. $cmd = sprintf('pdftk "%s" data_dump | grep Bookmark', $juridicus_protokolle->getPath() );
  404. if (!$process->isSuccessful()) {
  405. $this->logger->err(sprintf('Extracting Bookmarks failed', $cmd));
  406. } else {
  407. $bookmark_string = $process->getOutput();
  408. preg_match_all('#BookmarkTitle: (.*?)\s*BookmarkLevel: \d+\s*BookmarkPageNumber: (\d+)#s', $bookmark_string, $m);
  409. var_dump($m);
  410. // write pdf_marks
  411. }
  412. */
  413. $merge_path = tempnam($dir, "protokollmappe_");
  414. chmod($merge_path, 0644);
  415. $builder = new ProcessBuilder();
  416. $builder->add('pdftk');
  417. $builder->add($path);
  418. foreach ($juridicus_protokolle as $juridicus_protokoll) {
  419. $builder->add($juridicus_protokoll->getPath());
  420. }
  421. $builder->add('cat');
  422. $builder->add('output');
  423. $builder->add($merge_path);
  424. $process = $builder->getProcess();
  425. $process->run();
  426. if (!$process->isSuccessful()) {
  427. $this->logger->error(sprintf('Merging Command "%s" failed', $process->getCommandLine())); //changed from err()
  428. } else {
  429. unlink($path);
  430. $path = $merge_path;
  431. }
  432. }
  433. // Entity vervollständigen und speichern
  434. $pdf
  435. ->setAnzahlProtokolle($anzahl_protokolle)
  436. ->setMimeType('application/pdf')
  437. ->setPath($path)
  438. ->setSize(filesize($path))
  439. ;
  440. $this->em->persist($pdf);
  441. return $pdf;
  442. }
  443. /**
  444. *
  445. * @param \JF\JuridicusBundle\Services\KundePruefung $buchung
  446. * @param \DateTime $datum
  447. * @param $gender
  448. */
  449. public function createRechnung(KundePruefung $buchung, \DateTime $datum, $gender)
  450. {
  451. $kunde = $buchung->getKunde();
  452. $gebuehr_typ = $buchung->getGebuehr()->getTyp();
  453. $rechnung = $buchung->getRechnung($gebuehr_typ);
  454. if (!$rechnung) {
  455. // Rechnung rückwirkend erstellen
  456. $rechnung = new Rechnung();
  457. $rechnung
  458. ->setBuchung($buchung)
  459. ->setKunde($buchung->getKunde())
  460. ->setTyp($gebuehr_typ)
  461. ->setBetrag($buchung->getBetragGebuehr())
  462. ;
  463. // Rechnungsdatum ermitteln
  464. $email_rechnung = $buchung->getEmailRechnung();
  465. if ($email_rechnung) {
  466. $rechnung->setCreatedAt($email_rechnung->getCreatedAt());
  467. }
  468. $this->em->getRepository('JFJuridicusBundle:Rechnung')->insertMitNummer($rechnung);
  469. }
  470. $rechnungsnummer = $rechnung->getNummer();
  471. $tcpdf = $this->tcpdf->create();
  472. $params = $this->params;
  473. // TCPDF konfigurieren
  474. $tcpdf->SetPrintHeader(false);
  475. $tcpdf->SetPrintFooter(false);
  476. $tcpdf->SetCreator($params['pdf_creator']);
  477. $tcpdf->SetAuthor($params['pdf_author']);
  478. $tcpdf->SetTitle('Rechnung');
  479. $tcpdf->SetSubject('Rechnung');
  480. $tcpdf->SetKeywords('Juristischer Verlag Juridicus');
  481. $tcpdf->SetMargins(25, 13, 18);
  482. $tcpdf->SetAutoPageBreak(false, 0);
  483. $tcpdf->setLanguageArray(self::$tcpdf_language);
  484. $tcpdf->setFontSubsetting();
  485. $tcpdf->setFont('dejavusans');
  486. $tcpdf->AddPage();
  487. $tcpdf->Image($params['k_path_images'] . 'juridicus_square.png', '', '', 44.1, 0, '', '', 'N', true, 300, 'R');
  488. $tcpdf->SetFont('', '', 6);
  489. $str = 'Juristischer Verlag Juridicus GmbH | Kleienpfad 23 | 50933 Köln ';
  490. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  491. $tcpdf->Ln(5);
  492. // Adresse
  493. $tcpdf->SetFont('', '', 12);
  494. $str = $kunde->getName();
  495. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  496. $str = $kunde->getStrasseAndHausnummer();
  497. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  498. $str = $kunde->getPlzAndOrt();
  499. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  500. $tcpdf->Ln(43);
  501. $tcpdf->SetFont('', '', 11);
  502. $str = sprintf('Köln, den %s', $datum->format('d.m.Y'));
  503. $tcpdf->Cell(0, 0, $str, 0, 1, 'R');
  504. $tcpdf->Ln(4);
  505. $tcpdf->SetFont('', 'B', 11);
  506. $str = 'Bezug von Prüfungsprotokollen';
  507. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  508. $str = sprintf('RE-Nr. %s', $rechnungsnummer);
  509. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  510. $tcpdf->Ln(4);
  511. $tcpdf->SetFont('', '', 11);
  512. if ($gender == 'm') {
  513. $str = sprintf('Sehr geehrter Herr %s,', $kunde->getNachname());
  514. } elseif ($gender == 'f') {
  515. $str = sprintf('Sehr geehrte Frau %s,', $kunde->getNachname());
  516. } else {
  517. $str = sprintf('Sehr geehrte/r Frau/Herr %s,', $kunde->getNachname());
  518. }
  519. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  520. $tcpdf->Ln(4);
  521. $str = sprintf('für den Bezug der Prüfungsprotokolle stellen wir vereinbarungsgemäß den Betrag von %s € in '
  522. . 'Rechnung. In diesem Betrag ist aufgrund einer Umsatzsteuerbefreiung nach § 4 Nr. 21 a) bb) '
  523. . 'UStG Umsatzsteuer nicht enthalten.', number_format($buchung->getBetragGebuehr(), 2, ',', '.')
  524. );
  525. $tcpdf->MultiCell(0, 0, $str, 0, 'L');
  526. $str = 'Bitte überweisen Sie das Geld innerhalb der nächsten 7 Tage auf das untenstehende Konto.';
  527. $tcpdf->MultiCell(0, 0, $str, 0, 'L');
  528. $tcpdf->Ln(4);
  529. $str = 'Mit freundlichen Grüßen';
  530. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  531. $tcpdf->Ln(4);
  532. $tcpdf->Image($params['k_path_images'] . 'signature.jpg', '', '', 33.1, 0, '', '', 'N', true, 300, 'L');
  533. $tcpdf->Ln(4);
  534. $str = 'Wollburg';
  535. $tcpdf->cell(0, 0, $str, 0, 1, 'L');
  536. $str = 'Rechtsanwältin';
  537. $tcpdf->cell(0, 0, $str, 0, 1, 'L');
  538. // Footer
  539. $tcpdf->setY(258);
  540. $tcpdf->Image($params['k_path_images'] . 'footer.png', '', '', 159.6, 0, '', '', 'N', true, 300, 'L');
  541. return $tcpdf->Output('Rechnung.pdf', 'S');
  542. }
  543. /**
  544. *
  545. * @param AboZeitraum $zeitraum
  546. * @return string|null
  547. */
  548. public function createAboRechnung(AboZeitraum $zeitraum)
  549. {
  550. if ($zeitraum->getPreis() == 0) {
  551. return null;
  552. }
  553. $abo = $zeitraum->getAbo();
  554. if ($abo->getGutschein()) {
  555. return null;
  556. }
  557. $datum = $zeitraum->getDatumStart();
  558. $posten = $zeitraum->getRechnungsposten();
  559. $preis = $posten['summe'];
  560. $zeitschrift = $abo->getZeitschriftLang();
  561. $rechnung = $zeitraum->getRechnung();
  562. if (!$rechnung) {
  563. $rechnung = new Rechnung();
  564. $rechnung
  565. ->setAboZeitraum($zeitraum)
  566. ->setKunde($abo->getKunde())
  567. ->setTyp(Rechnung::TYP_ABOGEBUEHR)
  568. ->setBetrag($preis)
  569. ;
  570. $this->em->getRepository('JFJuridicusBundle:Rechnung')->insertMitNummer($rechnung);
  571. }
  572. $rechnungsnummer = $rechnung->getNummer();
  573. $tcpdf = $this->tcpdf->create();
  574. $params = $this->params;
  575. // TCPDF konfigurieren
  576. $tcpdf->SetPrintHeader(false);
  577. $tcpdf->SetPrintFooter(false);
  578. $tcpdf->SetCreator($params['pdf_creator']);
  579. $tcpdf->SetAuthor($params['pdf_author']);
  580. $tcpdf->SetTitle('Rechnung');
  581. $tcpdf->SetSubject('Rechnung');
  582. $tcpdf->SetKeywords('Juristischer Verlag Juridicus');
  583. $tcpdf->SetMargins(25, 13, 18);
  584. $tcpdf->SetAutoPageBreak(false, 0);
  585. $tcpdf->setLanguageArray(self::$tcpdf_language);
  586. $tcpdf->setFontSubsetting();
  587. $tcpdf->SetFont('arial');
  588. $tcpdf->AddPage();
  589. $tcpdf->Image($params['k_path_images'] . 'juridicus_square.png', '', '', 44.1, 0, '', '', 'N', true, 300, 'R');
  590. $tcpdf->SetFont('', '', 6);
  591. $str = 'Juristischer Verlag Juridicus GmbH | Kleienpfad 23 | 50933 Köln ';
  592. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  593. $tcpdf->Ln(5);
  594. // Adresse
  595. $tcpdf->SetFont('', '', 11);
  596. $tcpdf->MultiCell(0, 0, $abo->getAdresse(), 0, 'L');
  597. $tcpdf->setY(112);
  598. $tcpdf->SetFont('', 'B', 13);
  599. if ($abo->getTyp() === Abo::ABO_FULL) {
  600. $str = sprintf('ABO-JAHRESRECHNUNG %s', $datum->format('Y'));
  601. } else {
  602. $str = 'ABO-RECHNUNG';
  603. }
  604. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  605. $tcpdf->SetFont('', 'B', 10);
  606. $str = sprintf('%s Online', $zeitschrift);
  607. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  608. $tcpdf->Ln(4);
  609. $tcpdf->SetFont('', 'B', 9);
  610. $tcpdf->SetFillColor(220,220,220);
  611. $tcpdf->Cell(80);
  612. $str = 'Bitte bei Zahlung und Rückfragen angeben:';
  613. $tcpdf->Cell(80, 0, $str, 'LTR', 1, 'L', 1);
  614. $kennung = $abo->getAboKennung();
  615. $tcpdf->SetFont('', '', 9);
  616. $tcpdf->Cell(80);
  617. $tcpdf->Cell(40, 0, $kennung['kennung'].':', 'L', 0, 'L');
  618. $tcpdf->SetFont('', 'B', 9);
  619. $tcpdf->Cell(40, 0, $kennung['nummer'], 'R', 1, 'L');
  620. $tcpdf->SetFont('', '', 9);
  621. $tcpdf->Cell(80);
  622. $tcpdf->Cell(40, 0, 'Rechnungsnummer:', 'L', 0, 'L');
  623. $tcpdf->SetFont('', 'B', 9);
  624. $tcpdf->Cell(40, 0, $rechnung->getNummer(), 'R', 1, 'L');
  625. $tcpdf->SetFont('', '', 9);
  626. $tcpdf->Cell(80);
  627. $tcpdf->Cell(40, 0, 'Rechnungsdatum:', 'L', 0, 'L');
  628. $tcpdf->SetFont('', 'B', 9);
  629. $tcpdf->Cell(40, 0, $rechnung->getCreatedAt()->format('d.m.Y'), 'R', 1, 'L');
  630. $tcpdf->SetFont('', '', 9);
  631. $tcpdf->Cell(80);
  632. $tcpdf->Cell(40, 0, 'Ihre UST-ID:', 'L', 0, 'L');
  633. $tcpdf->SetFont('', 'B', 9);
  634. $tcpdf->Cell(40, 0, '', 'R', 1, 'L');
  635. $tcpdf->Cell(80);
  636. $tcpdf->Cell(80, 0, '', 'LR', 1, 'L');
  637. $tcpdf->Cell(80);
  638. $tcpdf->Cell(80, 0, '', 'LTBR', 1, 'L');
  639. $tcpdf->SetFont('', '', 7);
  640. $tcpdf->Cell(20, 0, 'Menge', 'TRB', 0, 'C');
  641. $tcpdf->Cell(48, 0, 'Titel', 'TRB', 0, 'C');
  642. $tcpdf->Cell(20, 0, 'Abopreis', 'TRB', 0, 'C');
  643. $tcpdf->Cell(20, 0, 'Rabatt %', 'TRB', 0, 'C');
  644. $tcpdf->Cell(20, 0, 'Einzelpreis', 'TRB', 0, 'C');
  645. $tcpdf->Cell(32, 0, 'Gesamtpreis', 'TRB', 1, 'C');
  646. $tcpdf->SetFont('', '', 9);
  647. $tcpdf->Cell(20, 0, '', 'R', 0);
  648. $tcpdf->Cell(48, 0, '', 'R', 0);
  649. $tcpdf->Cell(20, 0, '', 'R', 0);
  650. $tcpdf->Cell(20, 0, '', 'R', 0);
  651. $tcpdf->Cell(20, 0, '', 'R', 0);
  652. $tcpdf->Cell(32, 0, '', 'R', 1);
  653. foreach ($posten['einzel'] as $p) {
  654. $menge = '1';
  655. if (isset($p['zeitraum'])) {
  656. $menge .= sprintf("\n%s", $p['zeitraum']);
  657. }
  658. $preisFormatted = number_format($p['preis'],2,',','.');
  659. $rabattFormatted = number_format($p['rabatt_p'], 2, ',', '.');
  660. $restPreisFormatted = number_format($p['restpreis'], 2, ',', '.');
  661. $tcpdf->MultiCell(20, 12, $menge, 'R', 'C', 0, 0);
  662. $tcpdf->MultiCell(48, 12, $abo->getRechnungBezeichnung(), 'R', 'L', 0, 0);
  663. $tcpdf->MultiCell(20, 12, $preisFormatted, 'R', 'R', 0, 0);
  664. $tcpdf->MultiCell(20, 12, $rabattFormatted, 'R', 'R', 0 , 0);
  665. $tcpdf->MultiCell(20, 12, $restPreisFormatted, 'R', 'R', 0, 0);
  666. $tcpdf->MultiCell(32, 12, $restPreisFormatted, 'R', 'R', 0, 1);
  667. $tcpdf->Cell(20, 0, '', 'R', 0);
  668. $tcpdf->Cell(48, 0, '', 'R', 0);
  669. $tcpdf->Cell(20, 0, '', 'R', 0);
  670. $tcpdf->Cell(20, 0, '', 'R', 0);
  671. $tcpdf->Cell(20, 0, '', 'R', 0);
  672. $tcpdf->Cell(32, 0, '', 'R', 1);
  673. }
  674. $tcpdf->SetFont('', '', 9);
  675. $preisFormatted = number_format($preis, 2, ',', '.');
  676. $tcpdf->Cell(128, 0, 'Zwischensumme', 'T', 0, 'R');
  677. $tcpdf->Cell(32, 0, $preisFormatted, 'TR', 1, 'R');
  678. $tcpdf->Cell(128, 0, 'Versandkosten', 0, 0, 'R');
  679. $tcpdf->Cell(32, 0, '0,00', 'R', 1, 'R');
  680. $tcpdf->SetFont('', '', 7);
  681. $tcpdf->Cell(38, 0, 'Steuerl. Entgelt', 'TR', 0, 'L');
  682. $tcpdf->Cell(30, 0, 'MwSt %', 'LTR', 0, 'L');
  683. $tcpdf->Cell(30, 0, 'MwSt', 'LTR', 0, 'L');
  684. $tcpdf->Cell(30, 0, 'Endbetrag', 'LT', 0, 'L');
  685. $tcpdf->Cell(32, 0, '', 'TR', 1, 'L');
  686. if ($zeitschrift === 'Zeitschriftenauswertung') {
  687. // Keine Umsatzsteuer bei ZA
  688. $netto = $preis;
  689. $mwst = 0.0;
  690. $mwstProzent = 0.0;
  691. } else {
  692. $netto = $preis / 1.07;
  693. $mwst = $preis - $netto;
  694. $mwstProzent = 7.0;
  695. }
  696. $nettoFormatted = number_format($netto,2,',','.');
  697. $mwstFormatted = number_format($mwst,2,',','.');
  698. $mwstProzentFormatted = number_format($mwstProzent,2,',','.');
  699. $tcpdf->SetFont('', '', 9);
  700. $tcpdf->Cell(38, 5, $nettoFormatted, 'RB', 0, 'R');
  701. $tcpdf->Cell(30, 5, $mwstProzentFormatted, 'LRB', 0, 'R');
  702. $tcpdf->Cell(30, 5, $mwstFormatted, 'LRB', 0, 'R');
  703. $tcpdf->SetFont('', '', 9);
  704. $tcpdf->Cell(30, 5, 'EURO', 'LB', 0, 'R');
  705. $tcpdf->SetFont('', 'B', 10);
  706. $tcpdf->Cell(32, 5, $preisFormatted, 'RB', 1, 'R');
  707. $tcpdf->Ln(4);
  708. $tcpdf->SetFont('', '', 9);
  709. if ($abo->getSepa()) {
  710. $str = 'Der Rechnungsbetrag wird wie vereinbart mittels Lastschrift von Ihrem Konto eingezogen.';
  711. } else {
  712. $str = 'Der Rechnungsbetrag ist zahlbar innerhalb von 10 Tagen nach Zugang.';
  713. }
  714. $tcpdf->MultiCell(0, 0, $str, 0, 'L', 0, 1);
  715. $tcpdf->Ln(4);
  716. $str = 'Mit freundlichen Grüßen';
  717. $tcpdf->Cell(0, 0, $str, 0, 1, 'L');
  718. $tcpdf->Ln(1);
  719. $tcpdf->Image($params['k_path_images'] . 'signature.jpg', '', '', 25.0, 0, '', '', 'N', true, 300, 'L');
  720. $str = 'Wollburg';
  721. $tcpdf->cell(0, 0, $str, 0, 1, 'L');
  722. $str = 'Rechtsanwältin';
  723. $tcpdf->cell(0, 0, $str, 0, 1, 'L');
  724. // Footer
  725. $tcpdf->setY(258);
  726. $tcpdf->Image($params['k_path_images'] . 'footer.png', '', '', 159.6, 0, '', '', 'N', true, 300, 'L');
  727. return $tcpdf->Output('Rechnung.pdf', 'S');
  728. }
  729. /**
  730. *
  731. * @param \TCPDF $tcpdf
  732. * @param array $statistik
  733. */
  734. private function addStatistik(\TCPDF & $tcpdf, array $statistik)
  735. {
  736. if ($statistik) {
  737. $tcpdf->AddPage();
  738. $tcpdf->Bookmark('Meistgeprüfte Normen', 0, 0);
  739. $tcpdf->writeHTML('<h3>Meistgeprüfte Normen</h3>');
  740. $tcpdf->Cell(0, 10, 'Statistik der letzten 12 Monate (seit Datenerfassung)', 0, 1, 'L');
  741. $tcpdf->Ln(5);
  742. $tcpdf->SetFillColor(196);
  743. // Header
  744. $tcpdf->Cell(50, 6, "Norm", 1, 0, 'C', 1);
  745. $tcpdf->Cell(50, 6, "Anzahl Prüfungen", 1, 1, 'C', 1);
  746. // Body
  747. $fill = 0;
  748. foreach ($statistik as $row) {
  749. $text = sprintf('§ %s %s', $row['paragraph'], $row['kuerzel']);
  750. $link = sprintf('https://dejure.org/%s/%s.html', $row['link'], $row['paragraph']);
  751. $tcpdf->Cell(50, 6, $text, 1, 0, 'R', $fill, $link);
  752. $text = sprintf('%s (%s %%)', number_format($row['count'],0,',','.'), number_format($row['prozent'],2,',','.'));
  753. $tcpdf->Cell(50, 6, $text, 1, 1, 'R', $fill);
  754. $fill = !$fill;
  755. }
  756. }
  757. }
  758. /**
  759. *
  760. * @param array $liste
  761. * @return string path to created file
  762. */
  763. public function createAktenvortragMappe(array $liste)
  764. {
  765. $tcpdf = $this->tcpdf->create();
  766. $params = $this->params;
  767. // TCPDF konfigurieren
  768. $tcpdf->SetCreator($params['pdf_creator']);
  769. $tcpdf->SetAuthor($params['pdf_author']);
  770. $tcpdf->SetTitle('Aktenvorträge');
  771. $tcpdf->SetSubject('Aktenvorträge');
  772. $tcpdf->SetKeywords('Aktenvorträge');
  773. $tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], 'Aktenvorträge');
  774. $tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
  775. $tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
  776. $tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
  777. $tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
  778. $tcpdf->SetHeaderMargin($params['pdf_margin_header']);
  779. $tcpdf->SetFooterMargin($params['pdf_margin_footer']);
  780. $tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
  781. $tcpdf->setImageScale($params['pdf_image_scale_ratio']);
  782. $tcpdf->AddPage();
  783. foreach($liste as $protokoll_aktenvortrag) {
  784. $tcpdf->Bookmark('Aktenvortrag #'. $protokoll_aktenvortrag->getId(), 0, 0);
  785. $protokoll_aktenvortrag->addToPdf($tcpdf);
  786. $tcpdf->addPage();
  787. }
  788. $tcpdf->AddPage();
  789. // write the TOC title
  790. $tcpdf->SetFont('dejavusans', 'B', 16);
  791. $tcpdf->Cell(0, 0, 'Aktenvorträge', 0, 1, 'C');
  792. $tcpdf->Ln(5);
  793. $tcpdf->SetFont('dejavusans', '', 12);
  794. // add table of content at page 1
  795. $tcpdf->addTOC(1, 'dejavusans', '.', 'Aktenvorträge');
  796. $path = tempnam(sys_get_temp_dir(), "aktenvortragmappe_");
  797. chmod($path, 0666);
  798. $tcpdf->Output($path, 'F');
  799. return $path;
  800. }
  801. }