Datenstand V1.0
This commit is contained in:
163
inhalte/rechnung_gcreate.php
Normal file
163
inhalte/rechnung_gcreate.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
$sql = "SELECT * FROM ".PREFIX."_Gutschriften WHERE (Rechnung_Jahr = \"".$Jahr."\" AND Rechnung_ID = \"".$ID."\");";
|
||||
$result = $db->query($sql);
|
||||
|
||||
if ($nt = $result->fetch_assoc()) {
|
||||
while (strlen($nt['ID']) < $_SESSION['Firma']['Stellen']) {
|
||||
$nt['ID'] = "0".$nt['ID'];
|
||||
}
|
||||
exit("<h1>Zu dieser Rechnung existiert bereits eine Gutschrift mit der Nummer: ".$nt['Jahr']."_".$nt['ID']."!</h1>");
|
||||
} else {
|
||||
$sqlr = "SELECT * FROM ".PREFIX."_Rechnungen WHERE (Jahr = \"".$Jahr."\" AND ID = \"".$ID."\");";
|
||||
$resultr = $db->query($sqlr);
|
||||
$ntr = $resultr->fetch_assoc();
|
||||
if (!isset($_POST['step'])) {
|
||||
$sqlk = "SELECT Firma, Vorname, Nachname FROM ".PREFIX."_Kontakte WHERE (ID = \"".$ntr['Kontakt_ID']."\");";
|
||||
$resultk = $db->query($sqlk);
|
||||
$ntk = $resultk->fetch_assoc();
|
||||
while (strlen($ntr['ID']) < $_SESSION['Firma']['Stellen']) {
|
||||
$ntr['ID'] = "0".$ntr['ID'];
|
||||
}
|
||||
echo "<fieldset>\n";
|
||||
echo " <legend>Gutschrift erstellen</legend>\n";
|
||||
echo " <form action=\"index.php?".$_SERVER['QUERY_STRING']."\" method=\"post\">\n";
|
||||
echo " <input type=\"hidden\" name=\"step\" value=\"1\" />\n";
|
||||
echo " <input type=\"hidden\" name=\"ID\" value=\"".$_POST['ID']."\" />\n";
|
||||
echo " <input type=\"hidden\" name=\"Preis\" value=\"".$ntr['Preis']."\" />\n";
|
||||
echo " <p><b>Soll eine Gutschrift zu folgender Rechnung erstellt werden?</b></p>\n";
|
||||
echo " <label>Rechnung-Nr.</label>\n";
|
||||
echo " <label><b>".$ntr['Jahr']."_".$ntr['ID']."</b></label>\n";
|
||||
echo " <br />\n";
|
||||
echo " <label>Rechnungsbetrag</label>\n";
|
||||
echo " <label><b>".number_format($ntr['Preis'], '2', ',', '.')." €</b></label>\n";
|
||||
echo " <br />\n";
|
||||
echo " <label>Kunde</label>\n";
|
||||
echo " <label><b>";
|
||||
if ("" != $ntk['Firma']) {
|
||||
echo $ntk['Firma'].", ".$ntk['Nachname'];
|
||||
} else {
|
||||
echo $ntk['Vorname']." ".$ntk['Nachname'];
|
||||
}
|
||||
echo " </b></label>\n";
|
||||
echo " <br />\n";
|
||||
echo " <input type=\"submit\" class=\"button_ok\" name=\"formaction\" value=\"gcreate\" title=\"Weiter\" />\n";
|
||||
echo " <a href=\"index.php?section=".$_GET['section']."\"><img src=\"img/stop.png\" alt=\"Abbrechen\" title=\"Abbrechen\" /></a>\n";
|
||||
echo " <br />\n";
|
||||
echo " </form>\n";
|
||||
echo "</fieldset>\n";
|
||||
} else {
|
||||
if ("1" == $_POST['step']) {
|
||||
echo "<fieldset>\n";
|
||||
echo " <legend>Gutschrift erstellen</legend>\n";
|
||||
echo " <form action=\"index.php?".$_SERVER['QUERY_STRING']."\" method=\"post\">\n";
|
||||
echo " <input type=\"hidden\" name=\"step\" value=\"2\" />\n";
|
||||
echo " <input type=\"hidden\" name=\"ID\" value=\"".$_POST['ID']."\" />\n";
|
||||
echo " <input type=\"hidden\" name=\"Gesamt\" value=\"0\" />\n";
|
||||
echo " <p>Falls die Gutschrift über den Gesamtbetrag erstellt werden soll, setzen Sie hier das Häkchen!</p>\n";
|
||||
echo " <label>Rechnungsbetrag</label>\n";
|
||||
echo " <label>".number_format($_POST['Preis'], '2', ',', '.')." €</label>\n";
|
||||
echo " <br />\n";
|
||||
echo " <label>Gesamtbetrag</label>\n";
|
||||
echo " <input type=\"checkbox\" name=\"Gesamt\" value=\"1\" />\n";
|
||||
echo " <br />\n";
|
||||
echo " <label>oder</label>\n";
|
||||
echo " <br />\n";
|
||||
echo " <label>Gutschrift-Netto</label>\n";
|
||||
echo " <input class=\"short\" type=\"text\" name=\"Preis\" />\n";
|
||||
echo " <select style=\"width: auto;\" name=\"Typ\">\n";
|
||||
echo " <option value=\"Prozent\">%</option>\n";
|
||||
echo " <option value=\"Euro\">€</option>\n";
|
||||
echo " </select>\n";
|
||||
echo " <br /> <br />\n";
|
||||
echo " <input type=\"submit\" class=\"button_ok\" name=\"formaction\" value=\"gcreate\" title=\"Weiter\" />\n";
|
||||
echo " <a href=\"index.php?section=".$_GET['section']."\"><img src=\"img/stop.png\" alt=\"Abbrechen\" title=\"Abbrechen\" /></a>\n";
|
||||
echo " <br />\n";
|
||||
echo " </form>\n";
|
||||
echo "</fieldset>\n";
|
||||
} elseif ("2" == $_POST['step']) {
|
||||
echo "<br />\n";
|
||||
$sql = "SELECT * FROM ".PREFIX."_Rechnungen WHERE (Jahr = \"".$Jahr."\" AND ID = \"".$ID."\");";
|
||||
$result = $db->query($sql);
|
||||
$nt = $result->fetch_assoc();
|
||||
if ($_POST['Gesamt']) {
|
||||
$Preis = $nt['Preis'];
|
||||
} elseif ("Prozent" == $_POST['Typ']) {
|
||||
if ($_POST['Preis'] >= 100) {
|
||||
echo "<h2>Achtung: Sie haben mehr als den Gesamtbetrag der Rechnung gutgeschrieben!</h2>\n";
|
||||
}
|
||||
$Preis = $nt['Preis'] * $_POST['Preis'] / 100;
|
||||
} elseif ("Euro" == $_POST['Typ']) {
|
||||
if ($_POST['Preis'] >= $nt['Preis']) {
|
||||
echo "<h2>Achtung: Sie haben mehr als den Gesamtbetrag der Rechnung gutgeschrieben!</h2>\n";
|
||||
}
|
||||
$Preis = $_POST['Preis'];
|
||||
}
|
||||
echo "<br />\n";
|
||||
$sql = 'INSERT INTO '.PREFIX.'_Gutschriften (Jahr, ID, Kontakt_ID, Admin_ID, Rechnung_Jahr, Rechnung_ID, Gesamt, Preis, MwSt, Text, Datum) VALUES (YEAR(CURDATE()), NULL, "'.$nt['Kontakt_ID'].'", "'.$nt['Admin_ID'].'", "'.$Jahr.'", "'.$ID.'", "'.$_POST['Gesamt'].'", "'.$Preis.'", "'.$ntr['MwSt'].'", "'.addslashes(stripslashes($ntr['Text'])).'", CURDATE())';
|
||||
$stmt = $db->prepare($sql);
|
||||
if (!$stmt) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$db->error);
|
||||
}
|
||||
if (!$stmt->execute()) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
|
||||
}
|
||||
$sql = 'SELECT last_insert_id() AS last';
|
||||
$result = $db->query($sql);
|
||||
$nttemp = $result->fetch_assoc();
|
||||
$ID_New = $nttemp['last'];
|
||||
|
||||
if ($nt['Schluss_Rechnung']) {
|
||||
if ($_POST['Gesamt']) {
|
||||
$sqlp = "SELECT * FROM ".PREFIX."_Rechnung_Pos WHERE (Jahr = \"".$Jahr."\" AND Rechnung_ID = \"".$ID."\");";
|
||||
$resultp = $db->query($sqlp);
|
||||
while ($ntp = $resultp->fetch_assoc()) {
|
||||
$sql = "INSERT INTO ".PREFIX."_Gutschrift_Pos (ID, Jahr, Gutschrift_ID, Position, Anzahl, Bezeichnung, Preis, Feld1, Feld2, Feld3, Feld4, Feld5) VALUES (NULL, YEAR(CURDATE()), \"".$ID_New."\", \"".$ntp['Position']."\", \"".$ntp['Anzahl']."\", \"".addslashes(stripslashes($ntp['Bezeichnung']))."\", \"".$ntp['Preis']."\", \"".addslashes(stripslashes($ntp['Feld1']))."\", \"".addslashes(stripslashes($ntp['Feld2']))."\", \"".addslashes(stripslashes($ntp['Feld3']))."\", \"".addslashes(stripslashes($ntp['Feld4']))."\", \"".addslashes(stripslashes($ntp['Feld5']))."\");";
|
||||
$stmt = $db->prepare($sql);
|
||||
if (!$stmt) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$db->error);
|
||||
}
|
||||
if (!$stmt->execute()) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sql = "INSERT INTO ".PREFIX."_Gutschrift_Pos (ID, Jahr, Gutschrift_ID, Position, Anzahl, Bezeichnung, Preis) VALUES (NULL, YEAR(CURDATE()), \"".$ID_New."\", \"1\", \"1\", \"Gutschrift zu Schluss-Rechnung ".$Jahr."_".$ID."\", \"".$Preis."\");";
|
||||
$stmt = $db->prepare($sql);
|
||||
if (!$stmt) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$db->error);
|
||||
}
|
||||
if (!$stmt->execute()) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
|
||||
}
|
||||
}
|
||||
} elseif ($nt['Vorkasse']) {
|
||||
$sql = "INSERT INTO ".PREFIX."_Gutschrift_Pos (ID, Jahr, Gutschrift_ID, Position, Anzahl, Bezeichnung, Preis) VALUES (NULL, YEAR(CURDATE()), \"".$ID_New."\", \"1\", \"1\", \"Gutschrift zu Vorkasse-Rechnung ".$Jahr."_".$ID."\", \"".$Preis."\");";
|
||||
$stmt = $db->prepare($sql);
|
||||
if (!$stmt) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$db->error);
|
||||
}
|
||||
if (!$stmt->execute()) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
|
||||
}
|
||||
} else {
|
||||
$sql = "INSERT INTO ".PREFIX."_Gutschrift_Pos (ID, Jahr, Gutschrift_ID, Position, Anzahl, Bezeichnung, Preis) VALUES (NULL, YEAR(CURDATE()), \"".$ID_New."\", \"1\", \"1\", \"Gutschrift zu Abschlag-Rechnung ".$Jahr."_".$ID."\", \"".$Preis."\");";
|
||||
$stmt = $db->prepare($sql);
|
||||
if (!$stmt) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$db->error);
|
||||
}
|
||||
if (!$stmt->execute()) {
|
||||
die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
|
||||
}
|
||||
}
|
||||
|
||||
echo "<fieldset>\n";
|
||||
echo " <legend>Gutschrift wurde erstellt</legend>\n";
|
||||
echo " <form action=\"index.php?section=gut\" method=\"post\">\n";
|
||||
echo " <input type=\"hidden\" name=\"ID\" value=\"".date("Y")."_".$ID_New."\" />\n";
|
||||
echo " <input type=\"submit\" class=\"button_edit\" name=\"formaction\" value=\"edit\" title=\"Gutschrift bearbeiten\" />\n";
|
||||
echo " </form>\n";
|
||||
echo "</fieldset>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user