109 lines
4.7 KiB
PHP
109 lines
4.7 KiB
PHP
<h1>Mahnwesen</h1>
|
|
<?php
|
|
$test = explode("_", $_POST['ID']);
|
|
$ID = $test['1'];
|
|
$Jahr = $test['0'];
|
|
|
|
if (isset($_POST['mahnung']))
|
|
{
|
|
include __DIR__ . "/oposten_mahn2.php";
|
|
return (0);
|
|
}
|
|
if (!isset($_POST['ok']))
|
|
{
|
|
$sql = "SELECT Jahr, ID, Kontakt_ID, Admin_ID, Preis, MwSt, DATE_FORMAT(Datum, '%d.%m.%Y') AS Datum FROM " . PREFIX . "_Rechnungen WHERE (Jahr = \"" . $Jahr . "\" AND ID = \"" . $ID . "\");";
|
|
$result = $db->query($sql);
|
|
$nt = $result->fetch_assoc();
|
|
$sqlt = "SELECT * FROM " . PREFIX . "_Mahnungen WHERE (Referenz_Jahr = \"" . $nt['Jahr'] . "\" AND Referenz_ID = \"" . $nt['ID'] . "\");";
|
|
$resultt = $db->query($sqlt);
|
|
if ($ntt = $resultt->fetch_assoc())
|
|
{
|
|
echo "<h2>Zu dieser Rechnung wurde bereits eine 1. Mahnung erstellt!</h2>\n";
|
|
echo "<p>Falls Sie eine 2. (und letzte) Mahnung erstellen möchten, wählen Sie im Bereich \"Offene Posten\" unter \"1. Mahnungen\" die Schaltfläche \"2. Mahnung generieren\"\n";
|
|
return (0);
|
|
}
|
|
echo "<p>Soll eine Mahnung zur folgenden Rechnung erstellt werden:</p>\n";
|
|
$sql = "SELECT Firma, Vorname, Nachname FROM " . PREFIX . "_Kontakte WHERE ID = \"" . $nt['Kontakt_ID'] . "\";";
|
|
$resultk = $db->query($sql);
|
|
$ntk = $resultk->fetch_assoc();
|
|
while (strlen($nt['ID']) < $_SESSION['Firma']['Stellen'])
|
|
{
|
|
$nt['ID'] = "0" . $nt['ID'];
|
|
}
|
|
echo "<label>Rechnungs-Nr</label>\n";
|
|
echo "<label>" . $nt['Jahr'] . "_" . $nt['ID'] . "</label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
echo "<label>vom</label>\n";
|
|
echo "<label>" . $nt['Datum'] . "</label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
echo "<label>Kunde</label>\n";
|
|
echo "<label class=\"data\">";
|
|
if ("" != $ntk['Firma'])
|
|
{
|
|
echo $ntk['Firma'] . ",";
|
|
}
|
|
else
|
|
{
|
|
echo $ntk['Vorname'];
|
|
}
|
|
echo " " . $ntk['Nachname'];
|
|
echo "</label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
echo "<label>Betrag</label>\n";
|
|
echo "<label>" . number_format($nt['Preis'] * (1 + $nt['MwSt'] / 100), '2', ',', '.') . " €</label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
|
|
$sqlt = "SELECT SUM(Preis * (1 + MwSt / 100)) AS Preis FROM " . PREFIX . "_Teilzahlungen WHERE (Referenz_Jahr = \"" . $nt['Jahr'] . "\" AND Referenz_ID = \"" . $nt['ID'] . "\") ORDER BY Bezahlt_am ASC;";
|
|
$resultt = $db->query($sqlt);
|
|
$ntsum = $resultt->fetch_assoc();
|
|
|
|
echo "<label>- Teilzahlungen</label>\n";
|
|
echo "<label>" . number_format($ntsum['Preis'], '2', ',', '.') . " €</label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
|
|
echo "<label><b>= Restbetrag</b></label>\n";
|
|
echo "<label><b>" . number_format($nt['Preis'] * (1 + $nt['MwSt'] / 100) - $ntsum['Preis'], '2', ',', '.') . " €</b></label>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
|
|
echo "<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\" />\n";
|
|
echo " <br />\n";
|
|
echo " <input type=\"hidden\" name=\"table\" value=\"" . $Typ . "\" />\n";
|
|
echo " <input type=\"hidden\" name=\"ID\" value=\"" . $Jahr . "_" . $ID . "\" />\n";
|
|
echo " <input type=\"hidden\" name=\"Admin_ID\" value=\"" . $nt['Admin_ID'] . "\" />\n";
|
|
echo " <input type=\"hidden\" name=\"Kontakt_ID\" value=\"" . $nt['Kontakt_ID'] . "\" />\n";
|
|
echo " <input type=\"hidden\" name=\"formaction\" value=\"mahn\" />\n";
|
|
echo " <label>Zahlbar bis:</label>\n";
|
|
echo " <input type=\"text\" name=\"Z_Bis\" value=\"" . $_SESSION['Firma']['Z_Bis'] . "\" />\n";
|
|
echo " <img src=\"img/small_info.png\" title=\"Tage ab Datum der Erstellung.\" alt=\"Tage ab Datum der Erstellung.\" />\n";
|
|
echo " <br />\n";
|
|
echo " <input type=\"submit\" class=\"button_ok\" name=\"ok\" value=\"1\" title=\"Übernehmen\" />\n";
|
|
echo " <input type=\"submit\" class=\"button_stop\" name=\"formaction\" value=\"stop\" title=\"Abbrechen\" />\n";
|
|
echo "</form>\n";
|
|
echo "<br class=\"fix\" />\n";
|
|
}
|
|
else
|
|
{
|
|
$sql = 'INSERT INTO ' . PREFIX . '_Mahnungen (Jahr, ID, Nr, Kontakt_ID, Admin_ID, Referenz_Jahr, Referenz_ID, Z_Bis, Datum) VALUES (YEAR(CURDATE()), NULL, "1", "' . $_POST['Kontakt_ID'] . '", "' . $_POST['Admin_ID'] . '", "' . $Jahr . '", "' . $ID . '", "' . $_POST['Z_Bis'] . '", 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);
|
|
$nt = $result->fetch_assoc();
|
|
$ID = $nt['last'];
|
|
echo "<fieldset>\n";
|
|
echo " <legend>Mahnung wurde erstellt</legend>\n";
|
|
echo " <form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\">\n";
|
|
echo " <input type=\"hidden\" name=\"mahnung\" value=\"1\" />\n";
|
|
echo " <input type=\"hidden\" name=\"ID\" value=\"" . date("y") . "_" . $ID . "\" />\n";
|
|
echo " <input type=\"submit\" class=\"button_view\" name=\"formaction\" value=\"view\" title=\"Mahnung anzeigen\" />\n";
|
|
echo " </form>\n";
|
|
echo "</fieldset>\n";
|
|
|
|
} |