include("/home/rostrdbn/admin.rostroth.de/pages/includes/_config-mm.php");
require_once('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/fpdf.php');
require_once('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/fpdi.php');
$con = mysql_connect($db_host,$db_login_vvw,$db_pass_vvw);
$bill_id = $bill_id;
$action = $action;
$select = mysql_db_query($db_name_vvw,"select * from rr_bills where bill_id = '$bill_id' ");
$bill = mysql_fetch_array($select);
if($bill[adresszusatz] <> "") { $adresszusatz = $bill[adresszusatz]."\n"; } else { $adresszusatz = ""; }
$select_f = mysql_db_query($db_name_vvw,"select * from vvw_contacts where contact_id = '$bill[contact_id]' ");
$contact = mysql_fetch_array($select_f);
if(isset($vat)) { $vat = $vat; } else {
$vat = $contact[brutto_netto];
}
if(empty($vat)) { $vat = 'b'; }
$select_f = mysql_db_query($db_name_vvw,"select * from vvw_contacts where contact_id = '$bill[contact_id]' ");
$contact = mysql_fetch_array($select_f);
$firma = $contact[firma];
if($contact[nachname] || $contact[vorname]) { $kundeansprechpartner = $contact[vorname]." ".$contact[nachname]."\n"; } else { $kundeansprechpartner = ""; }
$bill_adresszusatz = $contact[adresszusatz];
$strasse = $contact[strasse];
$plz = $contact[plz];
$ort = $contact[ort];
$land = $contact[land];
$contact_id = $bill[contact_id];
$ustid = $contact[ustid];
//if($bill[adresszusatz] <> "") { $adresszusatz = $bill[adresszusatz]."\n"; } else { $adresszusatz = ""; }
$datum = $bill[datum];
$dt = explode("-", $datum);
$scheedatum = $dt[2].".".$dt[1].".".$dt[0];
$year = $dt[0];
$bill_id = $bill[bill_id];
$freitext = $bill[freitext];
$lieferanschrift = $bill[lieferanschrift];
$produkt = $bill[produkt];
$zahlart = $bill[zahlart];
$netto = $bill[netto];
$mwst = $bill[mwst];
$brutto = $bill[brutto];
$bearbeiter = $bill[bearbeiter];
// rechnungsempfänger auswählen
$adresszusatz = str_replace("trasse","traße",$adresszusatz);
if($bill[contact_id] == "0") { $bill_cnee = "BARVERKAUF\n$adresszusatz"; }
elseif($bill[contact_id] == "1") { $bill_cnee = $adresszusatz; }
elseif($bill[contact_id] > 1) {
// anschriftdaten aus dem kundenstamm
if($firma <> "") { $bill_cnee .= $firma."\n"; }
if($bill_adresszusatz <> "") { $bill_cnee .= $bill_adresszusatz."\n"; }
if($kundeansprechpartner <> "") { $bill_cnee .= $kundeansprechpartner.""; }
$bill_cnee .= $strasse."\n";
$bill_cnee .= $plz." ".$ort;
if($land != "Deutschland") { $bill_cnee .= "\n".$land; }
}
$euro = iconv('UTF-8', 'windows-1252', "€");
// betreff
$subject = iconv('UTF-8', 'windows-1252', 'Für Ihren Auftrag bedanken wir uns und möchten hiermit wie folgt in Rechnung stellen:');
// initiate FPDI
$pdf = new FPDI();
// add a page
$pdf->AddPage("P", "A4");
// set the source file
if(!empty($_REQUEST['template'])) { $template_file = $_REQUEST['template']; } else { $template_file = $bill['produkt']; }
$template = '/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/'.$template_file.'.pdf';
if (file_exists($template)) {
$pdf->setSourceFile('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/'.$template_file.'.pdf');
}
else{
$pdf->setSourceFile('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/r2.pdf');
}
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at position 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, 0, 0, 210);
$pdf->AddFont('Opensans-regular', '', 'Opensans-regular.php');
$pdf->AddFont('Opensans-bold', '', 'Opensans-bold.php');
// now write some text above the imported page
$pdf->SetFont('Opensans-regular', '', '9');
$pdf->SetTextColor(000, 0, 0);
$pdf->SetXY(28, 53);
/* ADRESSAT
Breite 180mm, Höhe 10mm
$string = Text schreiben
1 = mit Rahmen zeichnen
L = Text linkbündig
1 = mit Füllung
*/
$pdf->MultiCell( 100, 5, $bill_cnee , 0, 'L', 0);
$pdf->Ln(0);
// rechnungsspalte
$pdf->SetFont('Opensans-bold', '', '24');
$pdf->SetXY(28, 90.5);
$pdf->Write(0, 'RECHNUNG');
$pdf->SetFont('Opensans-regular', '', '8');
$pdf->SetXY(91.5, 88.5);
$pdf->Write(0, 'Rechnungsnummer: ');
$pdf->SetFont('Opensans-bold', '', '8');
$pdf->SetXY(120, 88.5);
$pdf->Write(0, $bill[bill_id]);
$pdf->SetFont('Opensans-regular', '', '8');
$pdf->SetXY(140, 88.5);
$pdf->Write(0, 'Datum:');
$pdf->SetFont('Opensans-bold', '', '8');
$pdf->SetXY(158, 88.5);
$pdf->Write(0, $scheedatum);
if($bill[produkt] == "MerchMe") { $kundeoderid = "Bestellnummer:"; $die_id = $bill[freitext]; }
else { $kundeoderid = "Kunden-Nummer:"; $die_id = $bill[contact_id]; }
$pdf->SetFont('Opensans-regular', '', '8');
$pdf->SetXY(91.5, 92);
$pdf->Write(0, $kundeoderid);
$pdf->SetFont('Opensans-bold', '', '8');
$pdf->SetXY(120, 92);
$pdf->Write(0, $die_id);
$pdf->SetFont('Opensans-regular', '', '8');
$pdf->SetXY(140, 92);
$pdf->Write(0, 'Bearbeiter:');
$pdf->SetFont('Opensans-bold', '', '8');
$pdf->SetXY(158, 92);
$pdf->Write(0, $bill[bearbeiter]);
$pdf->SetFont('Opensans-regular', '', '9');
$pdf->SetXY(28, 99);
$pdf->Write(0, $subject);
$pdf->SetFont('Opensans-regular', '', '6');
$pdf->SetXY(28, 104);
$pdf->Cell(7,5,'ANZ.','0','','C');
$pdf->Cell(3,5,'','0','','L');
$pdf->Cell(98,5,"PRODUKT/LEISTUNG/BESCHREIBUNG",'0');
$pdf->Cell(10,5,"(SD)",'0','','R');
$pdf->Cell(5,5,"",'0','','R');
if($vat == "b") {
$pdf->Cell(26,5,"EP BRUTTO",'0','','R');
$pdf->Cell(26,5,"GP BRUTTO",'0','','R');
}
if($vat == "n") {
$pdf->Cell(26,5,"EP NETTO",'0','','R');
$pdf->Cell(26,5,"GP NETTO",'0','','R');
}
$pdf->Ln(5);
$pdf->SetDrawColor(0, 0, 0);
$pdf->SetLineWidth(0.2);
$pdf->Line(29, 108, 202.7, 108);
$pdf->SetFont('Opensans-regular', '', '8');
$ust_5 = 0;
$ust_7 = 0;
$ust_16 = 0;
$ust_19 = 0;
$posinummer = 1;
$gesamtpreis = 0;
$x = "28";
$y = "108";
$get_pos1 = mysql_db_query($db_name_vvw,"select * from rr_bill_positions where bill_id = '$bill_id' order by posid");
$addpageexit = 0;
while($get_pos = mysql_fetch_array($get_pos1))
{
//Seitenumbruch
if($y > 250 && $addpageexit != "1") {
$pdf->AddPage(); //page break.
$x = 28;
$y2 = 110;
$template = '/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/'.$bill[produkt].'.pdf';
if (file_exists($template)) {
$pdf->setSourceFile('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/'.$bill[produkt].'.pdf');
}
else{
$pdf->setSourceFile('/home/rostrdbn/admin.rostroth.de/pages/rechnungen/layout/templates/r2.pdf');
}
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at position 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx, 0, 0, 210);
$addpageexit = 1;
$pdf->SetFont('Opensans-regular', '', '6');
$pdf->SetXY(28, 104);
$pdf->Cell(7,5,'ANZ.','0','','C');
$pdf->Cell(3,5,'','0','','L');
$pdf->Cell(98,5,"PRODUKT/LEISTUNG/BESCHREIBUNG",'0');
$pdf->Cell(10,5,"(SD)",'0','','R');
$pdf->Cell(5,5,"",'0','','R');
if($vat == "b") {
$pdf->Cell(26,5,"EP BRUTTO",'0','','R');
$pdf->Cell(26,5,"GP BRUTTO",'0','','R');
}
if($vat == "n") {
$pdf->Cell(26,5,"EP NETTO",'0','','R');
$pdf->Cell(26,5,"GP NETTO",'0','','R');
}
$pdf->Ln(5);
$pdf->SetDrawColor(0, 0, 0);
$pdf->SetLineWidth(0.2);
$pdf->Line(29, 108, 202.7, 108);
$pdf->SetFont('Opensans-regular', '', '8');
}
//Seitenumbruch ENDE
if($get_pos[mwst_satz] == "0") { $ust_teiler = "1";}
if($get_pos[mwst_satz] == "5") { $ust_teiler = "1.05";}
if($get_pos[mwst_satz] == "7") { $ust_teiler = "1.07";}
if($get_pos[mwst_satz] == "16") { $ust_teiler = "1.16";}
if($get_pos[mwst_satz] == "19") { $ust_teiler = "1.19";}
if($vat == "b") {
$poseinzelpreis = $get_pos[poseinzelpreis];
$poseinzelpreis = round($poseinzelpreis, 2);
$posgesamtpreis = $get_pos[anzahl]*$poseinzelpreis;
$poseinzelpreis_f = number_format($poseinzelpreis, 2, ',', '');
$posgesamtpreis_f = number_format($posgesamtpreis, 2, ',', '');
$gesamtpreis = $gesamtpreis+$posgesamtpreis;
if($get_pos[mwst_satz] == "0") { $ust_0 = $ust_0+$poseinzelpreis*$get_pos[anzahl]/$ust_teiler; }
if($get_pos[mwst_satz] == "5") { $ust_5 = $ust_5+$poseinzelpreis*$get_pos[anzahl]/$ust_teiler; }
if($get_pos[mwst_satz] == "7") { $ust_7 = $ust_7+$poseinzelpreis*$get_pos[anzahl]/$ust_teiler; }
if($get_pos[mwst_satz] == "16") { $ust_16 = $ust_16+$poseinzelpreis*$get_pos[anzahl]/$ust_teiler; }
if($get_pos[mwst_satz] == "19") { $ust_19 = $ust_19+$poseinzelpreis*$get_pos[anzahl]/$ust_teiler; }
}
if($vat == "n") {
$poseinzelpreis = $get_pos[poseinzelpreis]/$ust_teiler;
$poseinzelpreis = round($poseinzelpreis, 2);
$posgesamtpreis = $get_pos[anzahl]*$poseinzelpreis;
$poseinzelpreis_f = number_format($poseinzelpreis, 2, ',', '');
$posgesamtpreis_f = number_format($posgesamtpreis, 2, ',', '');
$gesamtpreis = $gesamtpreis+$posgesamtpreis;
if($get_pos[mwst_satz] == "0") { $ust_0 = $ust_0+$poseinzelpreis*$get_pos[anzahl]; }
if($get_pos[mwst_satz] == "5") { $ust_5 = $ust_5+$poseinzelpreis*$get_pos[anzahl]; }
if($get_pos[mwst_satz] == "7") { $ust_7 = $ust_7+$poseinzelpreis*$get_pos[anzahl]; }
if($get_pos[mwst_satz] == "16") { $ust_16 = $ust_16+$poseinzelpreis*$get_pos[anzahl]; }
if($get_pos[mwst_satz] == "19") { $ust_19 = $ust_19+$poseinzelpreis*$get_pos[anzahl]; }
}
if(!empty($y2)) { $y = $y2; unset($y2); } else {
if(isset($oink)) { $diff = $oink-$y; }
if($oink > $y) { $diff = $oink-$y; }
$y = $y+$diff+2;
}
$pdf->SetXY($x, $y);
//anzahl
$pdf->MultiCell(7, 3, $get_pos[anzahl], 0, C,0);
//beschreibung
$pdf->SetXY($x + 11, $y);
$pdf->MultiCell(98, 3, $get_pos[posbeschreibung], 0,L,0);
$oink = $pdf->GetY();
// ust satz
$pdf->SetXY($x + 110, $y);
$pdf->MultiCell(10, 3, $get_pos[mwst_satz]."%", 0,C,0);
//einzelpreis brutto
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, $poseinzelpreis_f." ".$euro, 0,R,0);
$oink2 = $pdf->GetY();
if($oink2 > $oink) {$oink = $oink2; }
//gesamtpreis brutto
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, $posgesamtpreis_f." ".$euro, 0,R,0);
}
$ust_5 = $ust_5/100*5;
$ust_7 = $ust_7/100*7;
$ust_16 = $ust_16/100*16;
$ust_19 = $ust_19/100*19;
if($oink > $y) { $diff = $oink-$y; }
$y = $y+$diff-2;
$pdf->SetDrawColor(0, 0, 0);
$pdf->SetLineWidth(0.2);
$y = $y+4;
$pdf->Line(29, $y, 202.7, $y);
////
/////
if($vat == "n") {
$pdf->SetFont('Opensans-regular', '', '8');
$y = $y+2;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "Nettobetrag:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($gesamtpreis, 2, ',', '')." ".$euro, 0,R,0);
if($ust_19 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "19% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_19, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_16 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "16% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_16, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_7 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "7% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_7, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_5 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "5% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_5, 2, ',', '')." ".$euro, 0,R,0);
}
$totalbrutto = $gesamtpreis+$ust_19+$ust_16+$ust_7+$ust_5;
$y = $y+4;
$pdf->SetFont('Opensans-bold', '', '8');
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "Gesamtbetrag:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($totalbrutto, 2, ',', '')." ".$euro, 0,R,0);
$totalbrutto_db = number_format($totalbrutto, 2, '.', '');
$mwst = number_format($ust_19+$ust_16+$ust_7+$ust_5, 2, '.', '');
$update2 = mysql_db_query($db_name_vvw, "update rr_bills set brutto='$totalbrutto_db', netto='$gesamtpreis',mwst='$mwst' where bill_id = '$bill_id'");
}
if($vat == "b") {
$totalbrutto = $gesamtpreis;
$pdf->SetFont('Opensans-bold', '', '8');
$y = $y+2;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "Gesamtbetrag:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($totalbrutto, 2, ',', '')." ".$euro, 0,R,0);
$pdf->SetFont('Opensans-regular', '', '8');
if($ust_19 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "davon 19% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_19, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_16 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "davon 16% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_16, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_7 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "davon 7% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_7, 2, ',', '')." ".$euro, 0,R,0);
}
if($ust_5 != 0) {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "davon 5% Ust.:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($ust_5, 2, ',', '')." ".$euro, 0,R,0);
}
$mwst = number_format($ust_19+$ust_16+$ust_7+$ust_5, 2, '.', '');
$netto = number_format($totalbrutto-$mwst, 2, '.', '');
$update = mysql_db_query($db_name_vvw, "update rr_bills set brutto='$totalbrutto', netto='$netto',mwst='$mwst' where bill_id = '$bill_id'");
}
if($vat == "b") {
$y = $y+4;
$pdf->SetXY($x + 125, $y);
$pdf->MultiCell(24, 3, "Nettobetrag:", 0,R,0);
$oink = $pdf->GetY();
//gesamtpreis NETTO
$pdf->SetXY($x + 150, $y);
$pdf->MultiCell(24, 3, number_format($netto, 2, ',', '')." ".$euro, 0,R,0);
}
$pdf->SetDrawColor(0, 0, 0);
$pdf->SetLineWidth(0.2);
$y = $y+4;
$pdf->Line(29, $y, 202.7, $y);
if($bill[lieferanschrift] <> "") {
$y = $y+4;
$pdf->SetXY(28, $y);
$lieferanschrift = str_replace("\n", ", ", $bill[lieferanschrift]);
$pdf->Write(0, 'Lieferanschrift: '.$lieferanschrift);
}
if($bill[produkt] != "MerchMe") {
// $pdf->Ln(10);
$pdf->SetFont('Opensans-regular', '', '8');
$y = $y+4;
$pdf->SetXY(28, $y);
$freitext = nl2br($bill[freitext]);
$freitext_laenge = strlen($freitext);
if($freitext_laenge > "100") {$y = $y+8; $dingens = '4'; }
$freitext = str_replace("
", " - ", $freitext);
$freitext = str_replace("
", " - ", $freitext);
$freitext_neu = "Referenz: ".$bill[produkt]." ".$freitext;
$pdf->Multicell(185,$dingens, $freitext_neu ,0,L,0);
$w=$pdf->GetStringWidth($freitext_neu)+29;
if($ustid <> "") {
$pdf->SetFont('Opensans-bold', '', '8');
$y = $y+4;
$pdf->SetXY(28, $y);
//$stichwort = iconv('UTF-8', 'windows-1252', $bill[stichwort]);
$ustid_ausgabe = "UstID: ".$ustid;
$pdf->Write(0, $ustid_ausgabe);
//$y = $y+2;
}
if($bill[stichwort] <> "") {
$pdf->SetFont('Opensans-bold', '', '8');
$y = $y+4;
$pdf->SetXY(28, $y);
//$stichwort = iconv('UTF-8', 'windows-1252', $bill[stichwort]);
$stichwort = $bill[stichwort];
$pdf->Write(0, $stichwort);
//$y = $y+2;
}
if($bill[status] != "PAID") {
$gb_b = number_format($totalbrutto, 2, ',', '');
$pdf->SetFont('Opensans-bold', '', '8');
$y = $y+6;
$pdf->SetXY(28, $y);
$zziel = iconv('UTF-8', 'windows-1252', 'Zahlungsziel: '.$gb_b.' € sofort.');
}
$pdf->Write(0, $zziel);
}
$pdf->SetFont('Opensans-regular', '', '8');
$y = $y+4;
$pdf->SetXY(28, $y);
$klausel = iconv('UTF-8', 'windows-1252', 'Sofern nicht anders vermerkt, entspricht das Rechnungsdatum dem Leistungszeitpunkt.
Waren und Leistungen bleiben bis zur vollständigen Bezahlung das Eigentum von RostRoth');
$pdf->MultiCell(185,4, $klausel,0,L,0);
$y = $y+12;
$pdf->SetFont('Opensans-regular', '', '8');
$pdf->SetXY(28, $y);
$ende = iconv('UTF-8', 'windows-1252', 'Wir bedanken uns für Ihr Vertrauen und freuen uns auf den nächsten Auftrag.');
$pdf->Write(0, $ende);
$pdf->Output('/home/rostrdbn/admin.rostroth.de/rechnungen/RE'.$bill[bill_id].'.pdf','F');
$pdf->Output('RE'.$bill[bill_id].'.pdf','I');
?>