<?php
if ($_SESSION['Firma']['KfZ'])
{
	$sqlkfz = "SELECT * FROM " . PREFIX . "_KfZ WHERE Kontakt_ID = \"" . $nt['Kontakt_ID'] . "\";";
	$resultkfz = $db->query($sqlkfz);
}
echo "<fieldset>\n";
echo "	<legend id=\"Setting\">" . $type . ": allgemeine Einstellungen</legend>\n";
echo "	<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "#Setting\" method=\"post\" />\n";
echo "		<input type=\"hidden\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_ok\" />\n";
echo "		<br style=\"clear: left;\"/>\n";
echo "		<label>Kunde</label>\n";
echo "		<select name=\"Kontakt_ID\" onchange=\"this.form.submit()\">\n";
while ($ntkn = $resultkn->fetch_assoc())
{
	echo "			<option value=\"" . $ntkn['ID'] . "\"";
	if ($nt['Kontakt_ID'] == $ntkn['ID'])
	{
		echo " selected=\"selected\" ";
		if ($ntkn['DSchutz'])
		{
			$DSchutz = 1;
		}
		else
		{
			$DSchutz = 0;
		}
	}
	echo ">" . $ntkn['Nachname'] . ", " . $ntkn['Vorname'] . " - " . $ntkn['Firma'] . "</option>\n";
}
echo "		</select>\n";
echo "		<br style=\"clear: left;\" />\n";

if ($_SESSION['Firma']['KfZ'])
{
	echo "		<label>Fahrzeug</label>\n";
	echo "		<select name=\"KfZ_ID\" onchange=\"this.form.submit()\">\n";
	while ($ntkfz = $resultkfz->fetch_assoc())
	{
		echo "			<option value=\"" . $ntkfz['ID'] . "\"";
		if ($nt['KfZ_ID'] == $ntkfz['ID'])
		{
			echo " selected=\"selected\" ";
		}
		echo ">" . $ntkfz['Kennzeichen'] . ", " . $ntkfz['Marke'] . " " . $ntkfz['Modell'] . "</option>\n";
	}
	echo "		</select>\n";
	echo "		<br style=\"clear: left;\" />\n";
}

if (!$DSchutz)
{
	echo "		<h2>Achtung: Es liegt keine Datenschutzerklärung vor!</h2>\n";
}
echo "		<label>Bearbeiter</label>\n";
echo "		<select name=\"Admin_ID\" onchange=\"this.form.submit()\">\n";
while ($ntan = $resultan->fetch_assoc())
{
	echo "			<option value=\"" . $ntan['ID'] . "\"";
	if ($nt['Admin_ID'] == $ntan['ID'])
	{
		echo " selected=\"selected\" ";
	}
	echo ">" . $ntan['Nachname'] . ", " . $ntan['Vorname'] . "</option>\n";
}
echo "		</select>\n";
echo "		<br style=\"clear: left;\" />\n";
if ($_SESSION['Firma']['KfZ'])
{
	if (("schrift" != $_GET['section']) AND ("liefer" != $_GET['section']))
	{
		echo "		<label>MwSt-Satz in %</label>\n";
		echo "		<input type=\"text\" name=\"MwSt\" value=\"" . $nt['MwSt'] . "\" />\n";
		echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
		echo "		<br />\n";
	}
}
else
{
	if (("lv" != $_GET['section']) AND ("schrift" != $_GET['section']) AND ("liefer" != $_GET['section']))
	{
		echo "		<label>MwSt-Satz in %</label>\n";
		echo "		<input type=\"text\" name=\"MwSt\" value=\"" . $nt['MwSt'] . "\" />\n";
		echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
		echo "		<br />\n";
	}
	if (("lv" == $_GET['section']) OR ("liefer" == $_GET['section']))
	{
		echo "		<h2 class=\"center\">Preise und Anzahl werden im " . $type . " nicht gedruckt.</h2>\n";
	}
}
if ("bestaet" == $_GET['section'])
{
	echo "		<label>Auftrag vom</label>\n";
	echo "		<input type=\"text\" name=\"A_Datum\" value=\"" . $nt['A_Datum'] . "\" />\n";
	echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
	echo "		<img src=\"img/small_info.png\" alt=\"Datum im Format: <TT.MM.JJJJ>!\" title=\"Datum im Format: <TT.MM.JJJJ>!\" />\n";
	echo "		<br />\n";
	echo "		<input type=\"hidden\" name=\"Preis_aus_Pos\" value=\"0\" />\n";
	echo "		<label>Preis aus Einzelpositionen?</label>\n";
	echo "		<input type=\"checkbox\" name=\"Preis_aus_Pos\" value=\"1\" ";
	if ("1" == $nt['Preis_aus_Pos'])
	{
		echo "checked=\"checked\" ";
	}
	echo " onchange=\"this.form.submit()\"/>\n";
	echo "		<br />\n";
	if (!$nt['Preis_aus_Pos'])
	{
		echo "		<label>Gesamtpreis zzgl. MwSt.</label>\n";
		echo "		<input type=\"text\" name=\"Auftrag_Preis\" value=\"" . $nt['Auftrag_Preis'] . "\" />\n";
		echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
		echo "		<br />\n";
	}
	else
	{
		echo "		<input type=\"hidden\" name=\"Auftrag_Preis\" value=\"" . $nts['Summe'] . "\" />\n";
	}
	if ($nt['Vorkasse'])
	{
		$sqlvk = "SELECT *, DATE_FORMAT(DATE_ADD(Datum, INTERVAL 14 DAY), '%d.%m.%Y') AS Datum FROM " . PREFIX . "_Rechnungen WHERE Vorkasse = \"1\" AND Auftrag_ID = \"" . $ID . "\";";
		$resultvk = $db->query($sqlvk);
		$ntvk = $resultvk->fetch_assoc();
		while (strlen($ntvk['ID']) < $_SESSION['Firma']['Stellen'])
		{
			$ntvk['ID'] = "0" . $ntvk['ID'];
		}
		echo "		<h2 class=\"center\">Falls Sie den Vorkasse-Betrag ändern möchten bearbeiten Sie bitte die Rechnung mit der Nummer " . $ntvk['Jahr'] . "_" . $ntvk['ID'] . "!</h2>\n";
	}
	else
	{
		echo "		<h2 class=\"center\">Falls Sie einen Vorkassebetrag vereinbart haben, erstellen Sie bitte aus dieser Bestätigung eine \"Vorkasse-Rechnung\"!</h2>";
	}
}
if ("Vorkasse-Rechnung" == $type)
{
	echo "		<label>Auftrags-Preis (netto)</label>\n";
	echo "		<label class=\"data\">" . number_format($ntab['Auftrag_Preis'], '2', ',', '.') . " &euro;</label>\n";
	echo "		<br />\n";
	echo "		<label>Vorkassebetrag (netto)</label>\n";
	echo "		<input type=\"text\" name=\"Preis\" value=\"" . $nt['Preis'] . "\" />\n";
	echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
	echo "		<br />\n";
}
if ("Abschlags-Rechnung" == $type)
{
	echo "		<label>Auftrags-Preis (netto):</label>\n";
	echo "		<label class=\"data\">" . number_format($ntab['Auftrag_Preis'], '2', ',', '.') . " &euro;</label>\n";
	echo "		<br />\n";
	if ($ntvk = $resultvk->fetch_assoc())
	{
		echo "		<label>Vorkassebetrag</label>\n";
		echo "		<label class=\"data\">" . number_format($ntvk['Preis'], '2', ',', '.') . " &euro;</label>\n";
		echo "		<br />\n";
	}
	echo "		<label>bisherige Abschlagzahlungen</label>\n";
	echo "		<label class=\"data\">" . number_format($ntaz['Preis'], '2', ',', '.') . " &euro;</label>\n";
	echo "		<br />\n";
	echo "		<label>Abschlagzahlung</label>\n";
	echo "		<input type=\"text\" name=\"Preis\" value=\"" . $nt['Preis'] . "\" />\n";
	echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
	echo "		<br />\n";
	echo "		<label>&nbsp;</label>\n";
	echo "		<label class=\"data\"><b>max. " . number_format($ntab['Auftrag_Preis'] - $ntvk['Preis'] - $ntaz['Preis'], '2', ',', '.') . " &euro;</b></label>\n";
	echo "		<br />\n";
}
if ("Schluss-Rechnung" == $type)
{
	echo "		<label>Auftrags-Preis (netto):</label>\n";
	echo "		<label class=\"data\">" . number_format($ntab['Auftrag_Preis'], '2', ',', '.') . " &euro;</label>\n";
	echo "		<br />\n";
	if ($ntvk = $resultvk->fetch_assoc())
	{
		echo "		<label>Vorkassebetrag</label>\n";
		echo "		<label class=\"data\">" . number_format($ntvk['Preis'], '2', ',', '.') . " &euro;</label>\n";
		echo "		<br />\n";
	}
	echo "		<label>bisherige Abschlagzahlungen</label>\n";
	echo "		<label class=\"data\">" . number_format($ntaz['Preis'], '2', ',', '.') . " &euro;</label>\n";
	echo "		<br />\n";
	$Preis = $ntab['Auftrag_Preis'] - $ntvk['Preis'] - $ntaz['Preis'];
	echo "		<input type=\"hidden\" name=\"Preis\" value=\"" . $Preis . "\" />\n";
}
if (("rechnung" == $_GET['section']) OR ("turnus" == $_GET['section']))
{
	echo "		<label>Rabatt in %</label>\n";
	echo "		<input type=\"text\" name=\"Rabatt\" value=\"" . $nt['Rabatt'] . "\" />\n";
	echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
	echo "		<br />\n";
	echo "		<label>Skonto in %</label>\n";
	echo "		<input type=\"text\" name=\"Skonto\" value=\"" . $nt['Skonto'] . "\" />\n";
}
if ("turnus" == $_GET['section'])
{
	echo "		<br />\n";
	echo "		<label>nächste Erstellung</label>\n";
	echo "		<input type=\"text\" name=\"Datum\" value=\"" . $nt['Datum'] . "\" />\n";
	echo "		<input type=\"submit\" name=\"formaction\" value=\"edit\" title=\"Einstellungen &uuml;bernehmen\" class=\"button_small_ok\" />\n";
	echo "		<img src=\"img/small_info.png\" alt=\"Datum im Format: <TT.MM.JJJJ>!\" title=\"Datum im Format: <TT.MM.JJJJ>!\" />\n";
}
echo "		<input type=\"hidden\" name=\"ID\" value=\"" . $Jahr . "_" . $ID . "\" />\n";
echo "		<input type=\"hidden\" name=\"action\" value=\"settings\" />\n";
echo "		<br />\n";
echo "	</form>\n";
echo "</fieldset>\n";
echo "<br />\n";