Hanno Böck To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/ Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code. */ require_once('session/start.php'); require_once('invoice.php'); require_once('inc/security.php'); require_role(ROLE_CUSTOMER); $invoice_id = (int) $_GET['id']; $items = invoice_items($invoice_id); $invoice = invoice_details($invoice_id); $outformat = 'html'; if (isset($_REQUEST['out']) && $_REQUEST['out'] == 'pdf') { $outformat = 'pdf'; } // Footer $footer = ''; $html = 'Rechnung Nr. '.$invoice_id.' '; // Folding Marks $html .= '
'; if ($outformat == 'pdf') { $html .= $footer; } $address = invoice_address($invoice['kunde']); // Address Field $html .= '
schokokeks.org · Köchersberg 32 · 71540 Murrhardt

'.($address['company'] != null ? $address['company'].'
' : '').$address['name'].'
'.$address['address'].'
'.($address['country'] != 'DE' ? $address['country'].'-' : '').$address['zip'].' '.$address['city'].'

'; // Right col $html .= '

schokokeks.org GbR
Bernd Wurst / Johannes Böck
Köchersberg 32
71540 Murrhardt

Tel: 07192-936432
E-Mail: root@schokokeks.org

'; // Caption / Invoice-Details $html .= '
Rechnung
Bei Fragen bitte immer angeben:
Rechnungsdatum:'.date("d. m. Y", strtotime($invoice['datum'])).'
Rechnungsnummer:'.$invoice_id.'
Kundennummer:'.$invoice['kunde'].'
'; $anrede = 'Sehr geehrte Damen und Herren'; $parts = explode(' ', $address['name']); $nachname = array_pop($parts); if ($address['name']) { if ($address['salutation'] == 'Herr') { $anrede = 'Sehr geehrter Herr '.$nachname; } elseif ($address['salutation'] == 'Frau') { $anrede = 'Sehr geehrte Frau '.$nachname; } } // Salutation $html .= '

'.$anrede.',
hiermit stellen wir die nachfolgend genannten Posten in Rechnung.

'; // Table $html .= ''; $vattype = null; // An der ersten Zeile entscheidet sich, ob die gesamte Rechnung als Netto- oder Bruttorechnung erstellt wird $einzelsummen = array(); $summe = 0.0; $odd = true; foreach ($items as $item) { if ($vattype == 'gross' && $item['brutto'] == 0) { system_failure('Mixed gross and net positions'); } elseif ($vattype == 'net' && $item['brutto'] == 1) { system_failure('Mixed gross and net positions'); } else { $vattype = ($item['brutto'] == 1 ? 'gross' : 'net'); } $anzahl = $item['anzahl']; if (round($anzahl, 0) == $anzahl) { $anzahl = round($anzahl, 0); } $desc = $item['beschreibung']; if ($item['enddatum'] == null) { $desc .= '
(Leistungsdatum: '.$item['datum'].')'; } else { $desc .= '
(Leistungszeitraum: '.$item['datum'].' - '.$item['enddatum'].')'; } $epreis = $item['betrag']; if ($item['brutto'] == 0) { $epreis = $epreis * (1 + ($item['mwst'] / 100)); } $einheit = ($item['einheit'] ? $item['einheit'] : ''); $gesamt = $epreis * $item['anzahl']; $epreis = $epreis; if (array_key_exists($item['mwst'], $einzelsummen)) { $einzelsummen[$item['mwst']]['net'] += $gesamt / (1 + ($item['mwst'] / 100)); $einzelsummen[$item['mwst']]['vat'] += $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100); $einzelsummen[$item['mwst']]['gross'] += $gesamt; } else { $einzelsummen[$item['mwst']] = array('net' => $gesamt / (1 + ($item['mwst'] / 100)), 'vat' => $gesamt / (1 + ($item['mwst'] / 100)) * ($item['mwst'] / 100), 'gross' => $gesamt); } $summe += $gesamt; $html .= ""; $html .= ""; $html .= "\n"; $odd = ! $odd; } $html .= ''; foreach ($einzelsummen as $percent => $sums) { $html .= ''; if (count($einzelsummen) > 1) { $html .= ''; } } $html .= '
Anz.   Beschreibung Einzelpreis Gesamtpreis
{$anzahl}{$einheit}{$desc}".number_format($epreis, 2, ',', '.')." €".number_format($gesamt, 2, ',', '.')." €
 
Nettobetrag ('.number_format($percent, 1, ',', '.').'% MwSt):'.number_format($sums['net'], 2, ',', '.').' €
MwSt-Betrag '.number_format($percent, 1, ',', '.').'%:'.number_format($sums['vat'], 2, ',', '.').' €
Brutto-Teilbetrag '.number_format($percent, 1, ',', '.').'% MwSt:'.number_format($sums['gross'], 2, ',', '.').' €
Rechnungsbetrag:'.number_format($summe, 2, ',', '.').' €
'; // Disclaimer if ($invoice['abbuchung'] == 1) { $sepamandat = get_sepamandat($invoice['sepamandat']); $iban = substr($sepamandat['iban'], 0, 8) . '**********' . substr($sepamandat['iban'], -4); $display_iban = $iban; for ($i = strlen($iban)-(strlen($iban)%4) ; $i != 0 ; $i -= 4) { $display_iban = substr($display_iban, 0, $i) . ' ' . substr($display_iban, $i); } $html .= '

Bitte nicht überweisen! Der fällige Betrag wird gemäß dem von Ihnen erteilten Lastschrift-Mandat in wenigen Tagen vom Konto mit der IBAN '.$display_iban.' bei der '.$sepamandat['bankname'].' (BIC: '.$sepamandat['bic'].') abgebucht. Diese Kontodaten beruhen auf dem Mandat Nr. '.$sepamandat['mandatsreferenz'].' vom '.$sepamandat['erteilt'].'. Unsere Gläubiger-ID lautet '.$sepamandat['glaeubiger_id'].'.

'; } else { $html .= '

Bitte begleichen Sie diese Rechnung umgehend nach Erhalt ohne Abzüge auf das unten angegebene Konto. Geben Sie im Verwendungszweck Ihrer Überweisung bitte die Rechnungsnummer '.$invoice_id.' an, damit Ihre Buchung korrekt zugeordnet werden kann.

'; } $html .= '

Wir danken Ihnen, dass Sie unser Angebot in Anspruch genommen haben und hoffen weiterhin auf eine gute Zusammenarbeit. Dieser Rechnung liegen die Allgemeinen Geschäftsbedingungen zum Zeitpunkt des Rechnungsdatums zugrunde, die Sie unter https://www.schokokeks.org/agb abrufen können.

'; if ($outformat == 'html') { $html .= $footer; } $html .= ' '; // Composer's auto-loading functionality require "vendor/autoload.php"; use Dompdf\Dompdf; //generate some PDFs! $dompdf = new DOMPDF(); //if you use namespaces you may use new \DOMPDF() $dompdf->setPaper('A4', 'portrait'); $dompdf->loadHtml($html); $dompdf->render(); if ($outformat == 'pdf') { $dompdf->stream("sample.pdf", array("Attachment"=>0)); } else { echo $html; } /*'); output("Summe aller Posten:"); output("{$summe} €\n"); output('
'); $l = get_lastschrift($invoice_id); if ($invoice['bezahlt'] == 1) { output('

Diese Rechnung ist bereits bezahlt.

'); } elseif ($l && $l['status'] == 'pending') { output('

Diese Rechnung wird am '.$l['buchungsdatum'].' per Lastschrift eingezogen.

'); } elseif ($l && $l['status'] == 'done') { output('

Diese Rechnung wurde am '.$l['buchungsdatum'].' per Lastschrift eingezogen.

'); } else { $qrcode_image = generate_qrcode_image_invoice($invoice_id); output('

GiroCode für Mobile Banking (SEPA Credit Transfer)

'); }*/