<?php
namespace JF\JuridicusBundle\Services;
use Doctrine\ORM\EntityManager;
//use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use JF\JuridicusBundle\Entity\Kunde;
use JF\JuridicusBundle\Entity\Pruefer;
use JF\JuridicusBundle\Entity\KundePruefung;
use JF\JuridicusBundle\Entity\Rechnung;
use JF\JuridicusBundle\Entity\ProtokollInfothekPruefer;
use JF\JuridicusBundle\Entity\ProtokollInfothekPruefung;
use JF\JuridicusBundle\Entity\PdfStempel;
use JF\JuridicusBundle\Entity\PdfProtokollmappePruefer;
use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer;
use JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefung;
use JF\JuridicusBundle\Entity\AboZeitraum;
use JF\JuridicusBundle\Entity\Abo;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use WhiteOctober\TCPDFBundle\Controller\TCPDFController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class PdfCreator
{
private EntityManagerInterface $em;
private LoggerInterface $logger;
private TCPDFController $tcpdfController;
private array $params;
public function __construct(
EntityManagerInterface $em,
LoggerInterface $logger,
ParameterBagInterface $bag
) {
$this->em = $em;
$this->logger = $logger;
$this->tcpdf = new TCPDFController('TCPDF'); // direkt instanziiert
$projectDir = $bag->get('kernel.project_dir');
$this->params = [
'pdf_creator' => 'Juridicus GmbH',
'k_path_images' => $projectDir.'/../src/JF/JuridicusBundle/Resources/public/images/',
'pdf_author' => 'Juridicus GmbH',
'pdf_page_format' => 'A4',
'pdf_page_orientation' => 'P',
'pdf_header_logo' => 'juridicus.png',
'pdf_unit' => 'mm',
'pdf_header_logo_width' => '30',
'pdf_margin_header' => '10',
'pdf_font_size_main' => '10',
'pdf_font_size_data' => '8',
'pdf_font_monospaced' => 'courier',
'pdf_margin_left' => '15',
'pdf_margin_right' => '15',
'pdf_margin_top' => '27',
'pdf_margin_footer' => '10',
'pdf_margin_bottom' => '25',
'pdf_image_scale_ratio' => '1',
'pdf_font_name_main' => 'dejavusans',
'pdf_font_name_data' => 'dejavusans'
];
}
/**
* Language definitions for TCPDF configuration
*
* @var array
*/
protected static $tcpdf_language = array(
'a_meta_charset' => 'UTF-8',
'a_meta_dir' => 'ltr',
'a_meta_language' => 'de',
'w_page' => 'Seite'
);
public function setEntityManager(EntityManager $em)
{
$this->em = $em;
return $this;
}
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
return $this;
}
public function setTcpdf(TCPDFController $tcpdf)
{
$this->tcpdf = $tcpdf;
return $this;
}
/**
*
* @param array $params
* @return \JF\JuridicusBundle\Services\PdfCreator
*/
public function setParameters(array $params)
{
$this->params = $params;
return $this;
}
/**
* erstellt einen Stempel
*
* @param \JF\JuridicusBundle\Entity\Kunde
* @return \JF\JuridicusBundle\Entity\PdfStempel | null
*/
public function createStempel(Kunde $kunde)
{
$tcpdf = $this->tcpdf->create();
$params = $this->params;
// TCPDF konfigurieren
$tcpdf->SetMargins(25, 1); // $params['pdf_margin_right'] - 15
$tcpdf->SetPrintHeader(false);
$tcpdf->SetPrintFooter(false);
$tcpdf->SetFont('dejavusans', '', 6);
$tcpdf->AddPage();
// alten Stempel finden
$pdf_stempel = $kunde->getPdfStempel();
if (null === $pdf_stempel) {
$pdf_stempel = new PdfStempel();
$pdf_stempel->setKunde($kunde);
}
$kunde->addToPdf($tcpdf);
// auf Platte speichern
$stempel_dir = $pdf_stempel->getDir();
$path = tempnam($stempel_dir, "stempel_");
chmod($path, 0666);
$tcpdf->Output($path, 'F');
// Entity vervollständigen und speichern
$pdf_stempel
->setMimeType('application/pdf')
->setPath($path)
->setSize(filesize($path))
;
$this->em->persist($pdf_stempel);
return $pdf_stempel;
}
/**
* erstellt ein Prüfungsprotokoll für alle Prüfer
*
* @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefung
* @return \JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefung | null
*/
public function createProtokollPruefung(ProtokollInfothekPruefung $protokoll_infothek_pruefung)
{
// altes Protokoll suchen
$pdf = $protokoll_infothek_pruefung->getPdfProtokollInfothekPruefung();
if (!$pdf) {
// neues Protokoll erstellen
$pdf = new PdfProtokollInfothekPruefung();
$pdf->setProtokollInfothekPruefung($protokoll_infothek_pruefung);
}
$tcpdf = $this->tcpdf->create();
$params = $this->params;
$title_string = sprintf('Juridicus - Protokoll #%d - %s', $protokoll_infothek_pruefung->getId(), $protokoll_infothek_pruefung->getDatum()->format('d.m.Y')
);
// TCPDF konfigurieren
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle($title_string);
$tcpdf->SetSubject($title_string);
$tcpdf->SetKeywords('Juridicus');
$tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
$tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
$tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
$tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
$tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
$tcpdf->SetHeaderMargin($params['pdf_margin_header']);
$tcpdf->SetFooterMargin($params['pdf_margin_footer']);
$tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
$tcpdf->setImageScale($params['pdf_image_scale_ratio']);
$tcpdf->setLanguageArray(self::$tcpdf_language);
$tcpdf->SetFont('dejavusans', '', 10);
foreach ($protokoll_infothek_pruefung->getProtokollInfothekPruefer() as $protokoll_infothek_pruefer) {
$pruefer_string = $protokoll_infothek_pruefer->getPruefer()->getFullText();
$tcpdf->AddPage();
$tcpdf->Bookmark($pruefer_string, 0, 0);
$tcpdf->Cell(0, 10, $pruefer_string, 0, 1, 'L');
$protokoll_infothek_pruefer->addToPdf($tcpdf);
}
// add a new page for TOC
$tcpdf->AddPage();
// write the TOC title
$tcpdf->SetFont('dejavusans', 'B', 16);
$tcpdf->MultiCell(0, 0, 'Inhaltsverzeichnis', 0, 'C');
$tcpdf->Ln();
// add table of content at page 1
$tcpdf->SetFont('dejavusans', '', 12);
$tcpdf->addTOC(1, 'dejavusans', '.', $title_string);
// auf Platte speichern
$dir = $pdf->getDir();
$path = tempnam($dir, $protokoll_infothek_pruefung->getId());
chmod($path, 0666);
$tcpdf->Output($path, 'F');
// Entity vervollständigen und speichern
$pdf
->setMimeType('application/pdf')
->setPath($path)
->setSize(filesize($path))
;
$this->em->persist($pdf);
return $pdf;
}
/**
* erstellt ein Prüfungsprotokoll für einen einzelnen Prüfer
*
* @param \JF\JuridicusBundle\Entity\ProtokollInfothekPruefer
* @return \JF\JuridicusBundle\Entity\PdfProtokollInfothekPruefer | null
*/
public function createProtokollPruefer(ProtokollInfothekPruefer $protokoll_infothek_pruefer)
{
// altes Protokoll vorhanden?
$pdf = $protokoll_infothek_pruefer->getPdfProtokollInfothekPruefer();
if (!$pdf) {
// neues Pdf erstellen
$pdf = new PdfProtokollInfothekPruefer();
$pdf->setProtokollInfothekPruefer($protokoll_infothek_pruefer);
}
$tcpdf = $this->tcpdf->create();
$params = $this->params;
// TCPDF konfigurieren
$protokoll_infothek_pruefung = $protokoll_infothek_pruefer->getProtokollInfothekPruefung();
$pruefer_string = $protokoll_infothek_pruefer->getPruefer()->getFullText();
$datum_string = $protokoll_infothek_pruefung->getDatum()->format('d.m.Y');
$title_string = sprintf('Juridicus - Neues Protokoll %s', $pruefer_string);
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle($title_string);
$tcpdf->SetSubject($title_string);
$tcpdf->SetKeywords('Juridicus', $pruefer_string);
$tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
$tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
$tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
$tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
$tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
$tcpdf->SetHeaderMargin($params['pdf_margin_header']);
$tcpdf->SetFooterMargin($params['pdf_margin_footer']);
$tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
$tcpdf->setImageScale($params['pdf_image_scale_ratio']);
$tcpdf->setLanguageArray(self::$tcpdf_language);
$tcpdf->SetFont('dejavusans', '', 10);
$tcpdf->AddPage();
$tcpdf->Cell(0, 10, sprintf('Protokoll - %s - %s', $pruefer_string, $datum_string), 0, 1, 'L');
$protokoll_infothek_pruefer->addToPdf($tcpdf);
// auf Platte speichern
$dir = $pdf->getDir();
$path = tempnam($dir, $protokoll_infothek_pruefer->getId());
chmod($path, 0666);
$tcpdf->Output($path, 'F');
// Entity vervollständigen und speichern
$pdf
->setMimeType('application/pdf')
->setPath($path)
->setSize(filesize($path))
;
$this->em->persist($pdf);
return $pdf;
}
/**
* erstellt eine Protokollmappe
*
* @param \JF\JuridicusBundle\Pruefer $pruefer
* @integer $examen
* @return \JF\JuridicusBundle\PdfProtokollmappePruefer|null
*/
public function createProtokollmappePruefer(Pruefer $pruefer, $examen)
{
$anzahl_protokolle = 0;
// html-Protokolle holen
$html_protokolle = $this->em->getRepository('JFJuridicusBundle:ProtokollHtml')->findByPrueferAndExamen($pruefer, $examen);
$anzahl_html_protokolle = count($html_protokolle);
$anzahl_protokolle += $anzahl_html_protokolle;
echo "Anzahl HTML Protokolle: ", $anzahl_html_protokolle, PHP_EOL;
// Infothek-Protokolle holen
$infothek_protokolle = $this->em->getRepository('JFJuridicusBundle:ProtokollInfothekPruefer')
->findByPrueferAndExamen($pruefer, $examen);
$anzahl_infothek_protokolle = count($infothek_protokolle);
$anzahl_protokolle += $anzahl_infothek_protokolle;
echo "Anzahl Infothek Protokolle: ", $anzahl_infothek_protokolle, PHP_EOL;
// Juridicus-Protokolle holen
$juridicus_protokolle = $this->em->getRepository('JFJuridicusBundle:PdfProtokollJuridicus')
->findByPrueferAndExamen($pruefer, $examen);
$anzahl_juridicus_protokolle = 0;
foreach ($juridicus_protokolle as $juridicus_protokoll) {
$anzahl_juridicus_protokolle += $juridicus_protokoll->getAnzahlProtokolle();
}
$anzahl_protokolle += $anzahl_juridicus_protokolle;
echo "Anzahl Juridicus-Protokolle: ", $anzahl_juridicus_protokolle, PHP_EOL;
// alte Protokollmappe holen
$pdf = $this->em->getRepository('JFJuridicusBundle:PdfProtokollmappePruefer')->findOneBy(array(
'pruefer' => $pruefer->getId(), 'examen' => $examen
));
if ($anzahl_protokolle == 0) {
if ($pdf) {
// alte Protokollmappe löschen
$this->em->remove($pdf);
}
return null;
}
// neue Protokollmappe erstellen?
if (!$pdf) {
$pdf = new PdfProtokollmappePruefer();
$pdf->setPruefer($pruefer)->setExamen($examen);
}
// TCPDF konfigurieren
$tcpdf = $this->tcpdf->create();
$params = $this->params;
$pruefer_string = $pruefer->getFullText();
$title_string = sprintf('Juridicus - %s', $pruefer_string);
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle($title_string);
$tcpdf->SetSubject($title_string);
$tcpdf->SetKeywords('Juridicus', $pruefer_string);
$tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], $title_string);
$tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
$tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
$tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
$tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
$tcpdf->SetHeaderMargin($params['pdf_margin_header']);
$tcpdf->SetFooterMargin($params['pdf_margin_footer']);
$tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
$tcpdf->setImageScale($params['pdf_image_scale_ratio']);
$tcpdf->setLanguageArray(self::$tcpdf_language);
$tcpdf->SetFont('dejavusans', '', 10);
// Statistik hinzufügen
$statistik = $this->em->getRepository('JFJuridicusBundle:ProtokollInfothekPruefer')->filterParagraphsByPruefer($pruefer,$examen);
$this->addStatistik($tcpdf, $statistik);
$j = 0;
// erste Protokolle der beiden Listen holen
$infothek_protokoll = array_shift($infothek_protokolle);
if ($infothek_protokoll) {
$infothek_datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
}
$html_protokoll = array_shift($html_protokolle);
if ($html_protokoll) {
$html_datum = $html_protokoll->getDatum();
}
while ($infothek_protokoll || $html_protokoll) {
// welches Protokoll ist das nächste?
if ($infothek_protokoll && $html_protokoll) {
$protokoll_select = ($html_datum === null || $html_datum < $infothek_datum) ? 'infothek' : 'html';
} elseif ($infothek_protokoll) {
$protokoll_select = 'infothek';
} elseif ($html_protokoll) {
$protokoll_select = 'html';
}
if ($protokoll_select === 'infothek') {
$datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
$protokoll = $infothek_protokoll;
// hole nächstes Infohek-Protokoll
$infothek_protokoll = array_shift($infothek_protokolle);
if ($infothek_protokoll) {
$infothek_datum = $infothek_protokoll->getProtokollInfothekPruefung()->getDatum();
}
} else {
$datum = $html_protokoll->getDatum();
$protokoll = $html_protokoll;
// hole nächstes HTML-Protokoll
$html_protokoll = array_shift($html_protokolle);
if ($html_protokoll) {
$html_datum = $html_protokoll->getDatum();
}
}
$j++;
if ($datum) {
$title_string = sprintf('Protokoll %d - %s', $j, $datum->format('d.m.Y'));
} else {
$title_string = sprintf('Protokoll %d', $j);
}
$tcpdf->AddPage();
$tcpdf->Bookmark($title_string, 0, 0);
$tcpdf->Cell(0, 10, $title_string, 0, 1, 'L');
$protokoll->addToPdf($tcpdf);
}
// Link auf Anhang, falls nicht alle Protokolle im Inhaltsverzeichnis auftauchen
if ($j > 0 && $anzahl_juridicus_protokolle > 0) {
$tcpdf->AddPage();
$tcpdf->Bookmark('Anhang', 0, 0);
$tcpdf->Ln(25);
$tcpdf->SetFont('dejavusans', 'B', 20);
$tcpdf->Cell(0, 0, 'Anhang', 0, 1, 'C');
$tcpdf->SetFont('dejavusans', '', 12);
$tcpdf->Cell(0, 0, '(Protokolle aus dem Zusammenschluss)', 0, 1, 'C');
}
// add a new page for TOC
$title_string = sprintf('Protokollmappe %s. Staatsexamen', $examen);
$tcpdf->AddPage();
// write the TOC title
$tcpdf->SetFont('dejavusans', 'B', 16);
$tcpdf->Cell(0, 0, $title_string, 0, 1, 'C');
$tcpdf->Ln(5);
$tcpdf->SetFont('dejavusans', '', 12);
// add table of content at page 1
$tcpdf->addTOC(1, 'dejavusans', '.', $pruefer_string);
// auf Platte speichern
$dir = $pdf->getDir();
$path = tempnam($dir, "protokollmappe_");
chmod($path, 0666);
$tcpdf->Output($path, 'F');
// Juridicus Protokolle mergen
if ($anzahl_juridicus_protokolle > 0) {
/**
* @todo restore bookmarks
*/
/*
$cmd = sprintf('pdftk "%s" data_dump | grep Bookmark', $juridicus_protokolle->getPath() );
if (!$process->isSuccessful()) {
$this->logger->err(sprintf('Extracting Bookmarks failed', $cmd));
} else {
$bookmark_string = $process->getOutput();
preg_match_all('#BookmarkTitle: (.*?)\s*BookmarkLevel: \d+\s*BookmarkPageNumber: (\d+)#s', $bookmark_string, $m);
var_dump($m);
// write pdf_marks
}
*/
$merge_path = tempnam($dir, "protokollmappe_");
chmod($merge_path, 0644);
$builder = new ProcessBuilder();
$builder->add('pdftk');
$builder->add($path);
foreach ($juridicus_protokolle as $juridicus_protokoll) {
$builder->add($juridicus_protokoll->getPath());
}
$builder->add('cat');
$builder->add('output');
$builder->add($merge_path);
$process = $builder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
$this->logger->error(sprintf('Merging Command "%s" failed', $process->getCommandLine())); //changed from err()
} else {
unlink($path);
$path = $merge_path;
}
}
// Entity vervollständigen und speichern
$pdf
->setAnzahlProtokolle($anzahl_protokolle)
->setMimeType('application/pdf')
->setPath($path)
->setSize(filesize($path))
;
$this->em->persist($pdf);
return $pdf;
}
/**
*
* @param \JF\JuridicusBundle\Services\KundePruefung $buchung
* @param \DateTime $datum
* @param $gender
*/
public function createRechnung(KundePruefung $buchung, \DateTime $datum, $gender)
{
$kunde = $buchung->getKunde();
$gebuehr_typ = $buchung->getGebuehr()->getTyp();
$rechnung = $buchung->getRechnung($gebuehr_typ);
if (!$rechnung) {
// Rechnung rückwirkend erstellen
$rechnung = new Rechnung();
$rechnung
->setBuchung($buchung)
->setKunde($buchung->getKunde())
->setTyp($gebuehr_typ)
->setBetrag($buchung->getBetragGebuehr())
;
// Rechnungsdatum ermitteln
$email_rechnung = $buchung->getEmailRechnung();
if ($email_rechnung) {
$rechnung->setCreatedAt($email_rechnung->getCreatedAt());
}
$this->em->getRepository('JFJuridicusBundle:Rechnung')->insertMitNummer($rechnung);
}
$rechnungsnummer = $rechnung->getNummer();
$tcpdf = $this->tcpdf->create();
$params = $this->params;
// TCPDF konfigurieren
$tcpdf->SetPrintHeader(false);
$tcpdf->SetPrintFooter(false);
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle('Rechnung');
$tcpdf->SetSubject('Rechnung');
$tcpdf->SetKeywords('Juristischer Verlag Juridicus');
$tcpdf->SetMargins(25, 13, 18);
$tcpdf->SetAutoPageBreak(false, 0);
$tcpdf->setLanguageArray(self::$tcpdf_language);
$tcpdf->setFontSubsetting();
$tcpdf->setFont('dejavusans');
$tcpdf->AddPage();
$tcpdf->Image($params['k_path_images'] . 'juridicus_square.png', '', '', 44.1, 0, '', '', 'N', true, 300, 'R');
$tcpdf->SetFont('', '', 6);
$str = 'Juristischer Verlag Juridicus GmbH | Kleienpfad 23 | 50933 Köln ';
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(5);
// Adresse
$tcpdf->SetFont('', '', 12);
$str = $kunde->getName();
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$str = $kunde->getStrasseAndHausnummer();
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$str = $kunde->getPlzAndOrt();
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(43);
$tcpdf->SetFont('', '', 11);
$str = sprintf('Köln, den %s', $datum->format('d.m.Y'));
$tcpdf->Cell(0, 0, $str, 0, 1, 'R');
$tcpdf->Ln(4);
$tcpdf->SetFont('', 'B', 11);
$str = 'Bezug von Prüfungsprotokollen';
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$str = sprintf('RE-Nr. %s', $rechnungsnummer);
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(4);
$tcpdf->SetFont('', '', 11);
if ($gender == 'm') {
$str = sprintf('Sehr geehrter Herr %s,', $kunde->getNachname());
} elseif ($gender == 'f') {
$str = sprintf('Sehr geehrte Frau %s,', $kunde->getNachname());
} else {
$str = sprintf('Sehr geehrte/r Frau/Herr %s,', $kunde->getNachname());
}
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(4);
$str = sprintf('für den Bezug der Prüfungsprotokolle stellen wir vereinbarungsgemäß den Betrag von %s € in '
. 'Rechnung. In diesem Betrag ist aufgrund einer Umsatzsteuerbefreiung nach § 4 Nr. 21 a) bb) '
. 'UStG Umsatzsteuer nicht enthalten.', number_format($buchung->getBetragGebuehr(), 2, ',', '.')
);
$tcpdf->MultiCell(0, 0, $str, 0, 'L');
$str = 'Bitte überweisen Sie das Geld innerhalb der nächsten 7 Tage auf das untenstehende Konto.';
$tcpdf->MultiCell(0, 0, $str, 0, 'L');
$tcpdf->Ln(4);
$str = 'Mit freundlichen Grüßen';
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(4);
$tcpdf->Image($params['k_path_images'] . 'signature.jpg', '', '', 33.1, 0, '', '', 'N', true, 300, 'L');
$tcpdf->Ln(4);
$str = 'Wollburg';
$tcpdf->cell(0, 0, $str, 0, 1, 'L');
$str = 'Rechtsanwältin';
$tcpdf->cell(0, 0, $str, 0, 1, 'L');
// Footer
$tcpdf->setY(258);
$tcpdf->Image($params['k_path_images'] . 'footer.png', '', '', 159.6, 0, '', '', 'N', true, 300, 'L');
return $tcpdf->Output('Rechnung.pdf', 'S');
}
/**
*
* @param AboZeitraum $zeitraum
* @return string|null
*/
public function createAboRechnung(AboZeitraum $zeitraum)
{
if ($zeitraum->getPreis() == 0) {
return null;
}
$abo = $zeitraum->getAbo();
if ($abo->getGutschein()) {
return null;
}
$datum = $zeitraum->getDatumStart();
$posten = $zeitraum->getRechnungsposten();
$preis = $posten['summe'];
$zeitschrift = $abo->getZeitschriftLang();
$rechnung = $zeitraum->getRechnung();
if (!$rechnung) {
$rechnung = new Rechnung();
$rechnung
->setAboZeitraum($zeitraum)
->setKunde($abo->getKunde())
->setTyp(Rechnung::TYP_ABOGEBUEHR)
->setBetrag($preis)
;
$this->em->getRepository('JFJuridicusBundle:Rechnung')->insertMitNummer($rechnung);
}
$rechnungsnummer = $rechnung->getNummer();
$tcpdf = $this->tcpdf->create();
$params = $this->params;
// TCPDF konfigurieren
$tcpdf->SetPrintHeader(false);
$tcpdf->SetPrintFooter(false);
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle('Rechnung');
$tcpdf->SetSubject('Rechnung');
$tcpdf->SetKeywords('Juristischer Verlag Juridicus');
$tcpdf->SetMargins(25, 13, 18);
$tcpdf->SetAutoPageBreak(false, 0);
$tcpdf->setLanguageArray(self::$tcpdf_language);
$tcpdf->setFontSubsetting();
$tcpdf->SetFont('arial');
$tcpdf->AddPage();
$tcpdf->Image($params['k_path_images'] . 'juridicus_square.png', '', '', 44.1, 0, '', '', 'N', true, 300, 'R');
$tcpdf->SetFont('', '', 6);
$str = 'Juristischer Verlag Juridicus GmbH | Kleienpfad 23 | 50933 Köln ';
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(5);
// Adresse
$tcpdf->SetFont('', '', 11);
$tcpdf->MultiCell(0, 0, $abo->getAdresse(), 0, 'L');
$tcpdf->setY(112);
$tcpdf->SetFont('', 'B', 13);
if ($abo->getTyp() === Abo::ABO_FULL) {
$str = sprintf('ABO-JAHRESRECHNUNG %s', $datum->format('Y'));
} else {
$str = 'ABO-RECHNUNG';
}
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->SetFont('', 'B', 10);
$str = sprintf('%s Online', $zeitschrift);
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(4);
$tcpdf->SetFont('', 'B', 9);
$tcpdf->SetFillColor(220,220,220);
$tcpdf->Cell(80);
$str = 'Bitte bei Zahlung und Rückfragen angeben:';
$tcpdf->Cell(80, 0, $str, 'LTR', 1, 'L', 1);
$kennung = $abo->getAboKennung();
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(80);
$tcpdf->Cell(40, 0, $kennung['kennung'].':', 'L', 0, 'L');
$tcpdf->SetFont('', 'B', 9);
$tcpdf->Cell(40, 0, $kennung['nummer'], 'R', 1, 'L');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(80);
$tcpdf->Cell(40, 0, 'Rechnungsnummer:', 'L', 0, 'L');
$tcpdf->SetFont('', 'B', 9);
$tcpdf->Cell(40, 0, $rechnung->getNummer(), 'R', 1, 'L');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(80);
$tcpdf->Cell(40, 0, 'Rechnungsdatum:', 'L', 0, 'L');
$tcpdf->SetFont('', 'B', 9);
$tcpdf->Cell(40, 0, $rechnung->getCreatedAt()->format('d.m.Y'), 'R', 1, 'L');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(80);
$tcpdf->Cell(40, 0, 'Ihre UST-ID:', 'L', 0, 'L');
$tcpdf->SetFont('', 'B', 9);
$tcpdf->Cell(40, 0, '', 'R', 1, 'L');
$tcpdf->Cell(80);
$tcpdf->Cell(80, 0, '', 'LR', 1, 'L');
$tcpdf->Cell(80);
$tcpdf->Cell(80, 0, '', 'LTBR', 1, 'L');
$tcpdf->SetFont('', '', 7);
$tcpdf->Cell(20, 0, 'Menge', 'TRB', 0, 'C');
$tcpdf->Cell(48, 0, 'Titel', 'TRB', 0, 'C');
$tcpdf->Cell(20, 0, 'Abopreis', 'TRB', 0, 'C');
$tcpdf->Cell(20, 0, 'Rabatt %', 'TRB', 0, 'C');
$tcpdf->Cell(20, 0, 'Einzelpreis', 'TRB', 0, 'C');
$tcpdf->Cell(32, 0, 'Gesamtpreis', 'TRB', 1, 'C');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(48, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(32, 0, '', 'R', 1);
foreach ($posten['einzel'] as $p) {
$menge = '1';
if (isset($p['zeitraum'])) {
$menge .= sprintf("\n%s", $p['zeitraum']);
}
$preisFormatted = number_format($p['preis'],2,',','.');
$rabattFormatted = number_format($p['rabatt_p'], 2, ',', '.');
$restPreisFormatted = number_format($p['restpreis'], 2, ',', '.');
$tcpdf->MultiCell(20, 12, $menge, 'R', 'C', 0, 0);
$tcpdf->MultiCell(48, 12, $abo->getRechnungBezeichnung(), 'R', 'L', 0, 0);
$tcpdf->MultiCell(20, 12, $preisFormatted, 'R', 'R', 0, 0);
$tcpdf->MultiCell(20, 12, $rabattFormatted, 'R', 'R', 0 , 0);
$tcpdf->MultiCell(20, 12, $restPreisFormatted, 'R', 'R', 0, 0);
$tcpdf->MultiCell(32, 12, $restPreisFormatted, 'R', 'R', 0, 1);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(48, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(20, 0, '', 'R', 0);
$tcpdf->Cell(32, 0, '', 'R', 1);
}
$tcpdf->SetFont('', '', 9);
$preisFormatted = number_format($preis, 2, ',', '.');
$tcpdf->Cell(128, 0, 'Zwischensumme', 'T', 0, 'R');
$tcpdf->Cell(32, 0, $preisFormatted, 'TR', 1, 'R');
$tcpdf->Cell(128, 0, 'Versandkosten', 0, 0, 'R');
$tcpdf->Cell(32, 0, '0,00', 'R', 1, 'R');
$tcpdf->SetFont('', '', 7);
$tcpdf->Cell(38, 0, 'Steuerl. Entgelt', 'TR', 0, 'L');
$tcpdf->Cell(30, 0, 'MwSt %', 'LTR', 0, 'L');
$tcpdf->Cell(30, 0, 'MwSt', 'LTR', 0, 'L');
$tcpdf->Cell(30, 0, 'Endbetrag', 'LT', 0, 'L');
$tcpdf->Cell(32, 0, '', 'TR', 1, 'L');
if ($zeitschrift === 'Zeitschriftenauswertung') {
// Keine Umsatzsteuer bei ZA
$netto = $preis;
$mwst = 0.0;
$mwstProzent = 0.0;
} else {
$netto = $preis / 1.07;
$mwst = $preis - $netto;
$mwstProzent = 7.0;
}
$nettoFormatted = number_format($netto,2,',','.');
$mwstFormatted = number_format($mwst,2,',','.');
$mwstProzentFormatted = number_format($mwstProzent,2,',','.');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(38, 5, $nettoFormatted, 'RB', 0, 'R');
$tcpdf->Cell(30, 5, $mwstProzentFormatted, 'LRB', 0, 'R');
$tcpdf->Cell(30, 5, $mwstFormatted, 'LRB', 0, 'R');
$tcpdf->SetFont('', '', 9);
$tcpdf->Cell(30, 5, 'EURO', 'LB', 0, 'R');
$tcpdf->SetFont('', 'B', 10);
$tcpdf->Cell(32, 5, $preisFormatted, 'RB', 1, 'R');
$tcpdf->Ln(4);
$tcpdf->SetFont('', '', 9);
if ($abo->getSepa()) {
$str = 'Der Rechnungsbetrag wird wie vereinbart mittels Lastschrift von Ihrem Konto eingezogen.';
} else {
$str = 'Der Rechnungsbetrag ist zahlbar innerhalb von 10 Tagen nach Zugang.';
}
$tcpdf->MultiCell(0, 0, $str, 0, 'L', 0, 1);
$tcpdf->Ln(4);
$str = 'Mit freundlichen Grüßen';
$tcpdf->Cell(0, 0, $str, 0, 1, 'L');
$tcpdf->Ln(1);
$tcpdf->Image($params['k_path_images'] . 'signature.jpg', '', '', 25.0, 0, '', '', 'N', true, 300, 'L');
$str = 'Wollburg';
$tcpdf->cell(0, 0, $str, 0, 1, 'L');
$str = 'Rechtsanwältin';
$tcpdf->cell(0, 0, $str, 0, 1, 'L');
// Footer
$tcpdf->setY(258);
$tcpdf->Image($params['k_path_images'] . 'footer.png', '', '', 159.6, 0, '', '', 'N', true, 300, 'L');
return $tcpdf->Output('Rechnung.pdf', 'S');
}
/**
*
* @param \TCPDF $tcpdf
* @param array $statistik
*/
private function addStatistik(\TCPDF & $tcpdf, array $statistik)
{
if ($statistik) {
$tcpdf->AddPage();
$tcpdf->Bookmark('Meistgeprüfte Normen', 0, 0);
$tcpdf->writeHTML('<h3>Meistgeprüfte Normen</h3>');
$tcpdf->Cell(0, 10, 'Statistik der letzten 12 Monate (seit Datenerfassung)', 0, 1, 'L');
$tcpdf->Ln(5);
$tcpdf->SetFillColor(196);
// Header
$tcpdf->Cell(50, 6, "Norm", 1, 0, 'C', 1);
$tcpdf->Cell(50, 6, "Anzahl Prüfungen", 1, 1, 'C', 1);
// Body
$fill = 0;
foreach ($statistik as $row) {
$text = sprintf('§ %s %s', $row['paragraph'], $row['kuerzel']);
$link = sprintf('https://dejure.org/%s/%s.html', $row['link'], $row['paragraph']);
$tcpdf->Cell(50, 6, $text, 1, 0, 'R', $fill, $link);
$text = sprintf('%s (%s %%)', number_format($row['count'],0,',','.'), number_format($row['prozent'],2,',','.'));
$tcpdf->Cell(50, 6, $text, 1, 1, 'R', $fill);
$fill = !$fill;
}
}
}
/**
*
* @param array $liste
* @return string path to created file
*/
public function createAktenvortragMappe(array $liste)
{
$tcpdf = $this->tcpdf->create();
$params = $this->params;
// TCPDF konfigurieren
$tcpdf->SetCreator($params['pdf_creator']);
$tcpdf->SetAuthor($params['pdf_author']);
$tcpdf->SetTitle('Aktenvorträge');
$tcpdf->SetSubject('Aktenvorträge');
$tcpdf->SetKeywords('Aktenvorträge');
$tcpdf->SetHeaderData($params['pdf_header_logo'], $params['pdf_header_logo_width'], 'Aktenvorträge');
$tcpdf->setHeaderFont(array($params['pdf_font_name_main'], '', $params['pdf_font_size_main']));
$tcpdf->setFooterFont(array($params['pdf_font_name_data'], '', $params['pdf_font_size_data']));
$tcpdf->SetDefaultMonospacedFont($params['pdf_font_monospaced']);
$tcpdf->SetMargins($params['pdf_margin_left'], $params['pdf_margin_top'], $params['pdf_margin_right']);
$tcpdf->SetHeaderMargin($params['pdf_margin_header']);
$tcpdf->SetFooterMargin($params['pdf_margin_footer']);
$tcpdf->SetAutoPageBreak(true, $params['pdf_margin_bottom']);
$tcpdf->setImageScale($params['pdf_image_scale_ratio']);
$tcpdf->AddPage();
foreach($liste as $protokoll_aktenvortrag) {
$tcpdf->Bookmark('Aktenvortrag #'. $protokoll_aktenvortrag->getId(), 0, 0);
$protokoll_aktenvortrag->addToPdf($tcpdf);
$tcpdf->addPage();
}
$tcpdf->AddPage();
// write the TOC title
$tcpdf->SetFont('dejavusans', 'B', 16);
$tcpdf->Cell(0, 0, 'Aktenvorträge', 0, 1, 'C');
$tcpdf->Ln(5);
$tcpdf->SetFont('dejavusans', '', 12);
// add table of content at page 1
$tcpdf->addTOC(1, 'dejavusans', '.', 'Aktenvorträge');
$path = tempnam(sys_get_temp_dir(), "aktenvortragmappe_");
chmod($path, 0666);
$tcpdf->Output($path, 'F');
return $path;
}
}