|
@@ -65,12 +65,12 @@ function getReservations() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Get reservation by code
|
|
|
|
|
|
|
+ * Get reservation by order number
|
|
|
*/
|
|
*/
|
|
|
-function getReservationByCode($code) {
|
|
|
|
|
|
|
+function getReservationByOrderNumber($orderNumber) {
|
|
|
$reservations = getReservations();
|
|
$reservations = getReservations();
|
|
|
foreach ($reservations as $reservation) {
|
|
foreach ($reservations as $reservation) {
|
|
|
- if ($reservation['code'] === $code) {
|
|
|
|
|
|
|
+ if (isset($reservation['id']) && $reservation['id'] === $orderNumber) {
|
|
|
return $reservation;
|
|
return $reservation;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -86,33 +86,30 @@ function saveReservations($reservations) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Generate unique reservation code
|
|
|
|
|
- */
|
|
|
|
|
-function generateReservationCode() {
|
|
|
|
|
- $code = '';
|
|
|
|
|
- $characters = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // Exclude confusing characters
|
|
|
|
|
- $max = strlen($characters) - 1;
|
|
|
|
|
-
|
|
|
|
|
- do {
|
|
|
|
|
- $code = '';
|
|
|
|
|
- for ($i = 0; $i < 6; $i++) {
|
|
|
|
|
- $code .= $characters[random_int(0, $max)];
|
|
|
|
|
- }
|
|
|
|
|
- // Check if code already exists
|
|
|
|
|
- $existing = getReservationByCode($code);
|
|
|
|
|
- } while ($existing !== null);
|
|
|
|
|
-
|
|
|
|
|
- return $code;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Generate reservation ID
|
|
|
|
|
|
|
+ * Generate order number
|
|
|
|
|
+ * Pattern: PREFIX-YEAR-SEQ
|
|
|
*/
|
|
*/
|
|
|
function generateReservationId() {
|
|
function generateReservationId() {
|
|
|
$reservations = getReservations();
|
|
$reservations = getReservations();
|
|
|
- $count = count($reservations) + 1;
|
|
|
|
|
$year = date('Y');
|
|
$year = date('Y');
|
|
|
- return sprintf('RES-%s-%03d', $year, $count);
|
|
|
|
|
|
|
+ $prefix = defined('ORDER_PREFIX') ? ORDER_PREFIX : 'ORD';
|
|
|
|
|
+ $max = 0;
|
|
|
|
|
+ $pattern = '/^' . preg_quote($prefix, '/') . '-\\d{4}-(\\d+)$/';
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($reservations as $reservation) {
|
|
|
|
|
+ if (!isset($reservation['id'])) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (preg_match($pattern, $reservation['id'], $matches)) {
|
|
|
|
|
+ $num = (int)$matches[1];
|
|
|
|
|
+ if ($num > $max) {
|
|
|
|
|
+ $max = $num;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $next = $max + 1;
|
|
|
|
|
+ return sprintf('%s-%s-%03d', $prefix, $year, $next);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -256,7 +253,6 @@ function createReservation($customerName, $customerEmail, $items) {
|
|
|
|
|
|
|
|
$reservation = [
|
|
$reservation = [
|
|
|
'id' => generateReservationId(),
|
|
'id' => generateReservationId(),
|
|
|
- 'code' => generateReservationCode(),
|
|
|
|
|
'customer_name' => $customerName,
|
|
'customer_name' => $customerName,
|
|
|
'customer_email' => $customerEmail,
|
|
'customer_email' => $customerEmail,
|
|
|
'items' => $items,
|
|
'items' => $items,
|
|
@@ -286,7 +282,6 @@ function createBackorderReservation($customerName, $customerEmail, $items) {
|
|
|
|
|
|
|
|
$reservation = [
|
|
$reservation = [
|
|
|
'id' => generateReservationId(),
|
|
'id' => generateReservationId(),
|
|
|
- 'code' => generateReservationCode(),
|
|
|
|
|
'customer_name' => $customerName,
|
|
'customer_name' => $customerName,
|
|
|
'customer_email' => $customerEmail,
|
|
'customer_email' => $customerEmail,
|
|
|
'items' => $items,
|
|
'items' => $items,
|
|
@@ -377,7 +372,7 @@ function markBackorderAvailable($reservationId) {
|
|
|
foreach ($reservations as &$reservation) {
|
|
foreach ($reservations as &$reservation) {
|
|
|
if ($reservation['id'] === $reservationId) {
|
|
if ($reservation['id'] === $reservationId) {
|
|
|
if (!isset($reservation['type']) || $reservation['type'] !== 'backorder') {
|
|
if (!isset($reservation['type']) || $reservation['type'] !== 'backorder') {
|
|
|
- return ['success' => false, 'message' => 'Diese Reservierung ist keine Nachbestellung.'];
|
|
|
|
|
|
|
+ return ['success' => false, 'message' => 'Diese Nachbestellung wurde bereits in eine Bestellung umgewandelt.'];
|
|
|
}
|
|
}
|
|
|
if (isset($reservation['backorder_status']) && $reservation['backorder_status'] === 'notified') {
|
|
if (isset($reservation['backorder_status']) && $reservation['backorder_status'] === 'notified') {
|
|
|
return ['success' => false, 'message' => 'Diese Nachbestellung wurde bereits informiert.'];
|
|
return ['success' => false, 'message' => 'Diese Nachbestellung wurde bereits informiert.'];
|
|
@@ -390,8 +385,18 @@ function markBackorderAvailable($reservationId) {
|
|
|
$size = isset($item['size']) ? $item['size'] : null;
|
|
$size = isset($item['size']) ? $item['size'] : null;
|
|
|
allocateStock($item['product_id'], $item['quantity'], $size);
|
|
allocateStock($item['product_id'], $item['quantity'], $size);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $reservation['backorder_status'] = 'notified';
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $now = new DateTime();
|
|
|
|
|
+ $expires = clone $now;
|
|
|
|
|
+ $expires->modify('+' . RESERVATION_EXPIRY_DAYS . ' days');
|
|
|
|
|
+
|
|
|
|
|
+ $reservation['type'] = 'regular';
|
|
|
|
|
+ $reservation['status'] = 'open';
|
|
|
|
|
+ $reservation['picked_up'] = false;
|
|
|
|
|
+ $reservation['expires'] = $expires->format('Y-m-d H:i:s');
|
|
|
|
|
+ if (isset($reservation['backorder_status'])) {
|
|
|
|
|
+ unset($reservation['backorder_status']);
|
|
|
|
|
+ }
|
|
|
saveReservations($reservations);
|
|
saveReservations($reservations);
|
|
|
|
|
|
|
|
sendBackorderAvailableEmail($reservation);
|
|
sendBackorderAvailableEmail($reservation);
|
|
@@ -475,19 +480,19 @@ function sendReservationEmails($reservation) {
|
|
|
<p>vielen Dank für Ihre Reservierung bei ' . SITE_NAME . '.</p>
|
|
<p>vielen Dank für Ihre Reservierung bei ' . SITE_NAME . '.</p>
|
|
|
|
|
|
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
|
- <h3 style="margin-top: 0; color: #f5f7fb;">Ihr Abholcode:</h3>
|
|
|
|
|
- <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['code']) . '</h2>
|
|
|
|
|
|
|
+ <h3 style="margin-top: 0; color: #f5f7fb;">Ihre Bestellnummer:</h3>
|
|
|
|
|
+ <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['id']) . '</h2>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Reservierungsdetails:</h3>
|
|
<h3>Reservierungsdetails:</h3>
|
|
|
- <p><strong>Reservierungsnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
|
|
|
|
+ <p><strong>Bestellnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
|
<p><strong>Gültig bis:</strong> ' . formatDate($reservation['expires']) . '</p>
|
|
<p><strong>Gültig bis:</strong> ' . formatDate($reservation['expires']) . '</p>
|
|
|
|
|
|
|
|
<h3>Reservierte Artikel:</h3>
|
|
<h3>Reservierte Artikel:</h3>
|
|
|
' . $itemsHtml . '
|
|
' . $itemsHtml . '
|
|
|
|
|
|
|
|
- <p><strong>Wichtig:</strong> Bitte bringen Sie diesen Abholcode zur Abholung mit. Die Reservierung ist bis zum ' . formatDate($reservation['expires']) . ' gültig.</p>
|
|
|
|
|
|
|
+ <p><strong>Wichtig:</strong> Bitte nennen Sie diese Bestellnummer bei der Abholung. Die Reservierung ist bis zum ' . formatDate($reservation['expires']) . ' gültig.</p>
|
|
|
|
|
|
|
|
<p>Mit freundlichen Grüßen<br>' . SITE_NAME . '</p>
|
|
<p>Mit freundlichen Grüßen<br>' . SITE_NAME . '</p>
|
|
|
</div>
|
|
</div>
|
|
@@ -497,7 +502,7 @@ function sendReservationEmails($reservation) {
|
|
|
sendEmail($reservation['customer_email'], $customerSubject, $customerMessage);
|
|
sendEmail($reservation['customer_email'], $customerSubject, $customerMessage);
|
|
|
|
|
|
|
|
// Admin email
|
|
// Admin email
|
|
|
- $adminSubject = 'Neue Reservierung: ' . $reservation['code'];
|
|
|
|
|
|
|
+ $adminSubject = 'Neue Reservierung: ' . $reservation['id'];
|
|
|
$adminMessage = '
|
|
$adminMessage = '
|
|
|
<html>
|
|
<html>
|
|
|
<head>
|
|
<head>
|
|
@@ -509,8 +514,8 @@ function sendReservationEmails($reservation) {
|
|
|
<p>Eine neue Reservierung wurde erstellt:</p>
|
|
<p>Eine neue Reservierung wurde erstellt:</p>
|
|
|
|
|
|
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px;">
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px;">
|
|
|
- <h3 style="margin-top: 0;">Abholcode:</h3>
|
|
|
|
|
- <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['code']) . '</h2>
|
|
|
|
|
|
|
+ <h3 style="margin-top: 0;">Bestellnummer:</h3>
|
|
|
|
|
+ <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['id']) . '</h2>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Kundendaten:</h3>
|
|
<h3>Kundendaten:</h3>
|
|
@@ -518,7 +523,7 @@ function sendReservationEmails($reservation) {
|
|
|
<p><strong>E-Mail:</strong> ' . htmlspecialchars($reservation['customer_email']) . '</p>
|
|
<p><strong>E-Mail:</strong> ' . htmlspecialchars($reservation['customer_email']) . '</p>
|
|
|
|
|
|
|
|
<h3>Reservierungsdetails:</h3>
|
|
<h3>Reservierungsdetails:</h3>
|
|
|
- <p><strong>Reservierungsnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
|
|
|
|
+ <p><strong>Bestellnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
|
<p><strong>Gültig bis:</strong> ' . formatDate($reservation['expires']) . '</p>
|
|
<p><strong>Gültig bis:</strong> ' . formatDate($reservation['expires']) . '</p>
|
|
|
|
|
|
|
@@ -563,12 +568,12 @@ function sendBackorderEmails($reservation) {
|
|
|
<p>vielen Dank für Ihre Nachbestellung bei ' . SITE_NAME . '.</p>
|
|
<p>vielen Dank für Ihre Nachbestellung bei ' . SITE_NAME . '.</p>
|
|
|
|
|
|
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
|
- <h3 style="margin-top: 0; color: #f5f7fb;">Ihr Abholcode:</h3>
|
|
|
|
|
- <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['code']) . '</h2>
|
|
|
|
|
|
|
+ <h3 style="margin-top: 0; color: #f5f7fb;">Ihre Bestellnummer:</h3>
|
|
|
|
|
+ <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['id']) . '</h2>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Nachbestellungsdetails:</h3>
|
|
<h3>Nachbestellungsdetails:</h3>
|
|
|
- <p><strong>Nachbestellungsnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
|
|
|
|
+ <p><strong>Bestellnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
|
|
|
|
|
|
<h3>Nachbestellte Artikel:</h3>
|
|
<h3>Nachbestellte Artikel:</h3>
|
|
@@ -588,7 +593,7 @@ function sendBackorderEmails($reservation) {
|
|
|
sendEmail($reservation['customer_email'], $customerSubject, $customerMessage);
|
|
sendEmail($reservation['customer_email'], $customerSubject, $customerMessage);
|
|
|
|
|
|
|
|
// Admin email
|
|
// Admin email
|
|
|
- $adminSubject = 'Neue Nachbestellung: ' . $reservation['code'];
|
|
|
|
|
|
|
+ $adminSubject = 'Neue Nachbestellung: ' . $reservation['id'];
|
|
|
$adminMessage = '
|
|
$adminMessage = '
|
|
|
<html>
|
|
<html>
|
|
|
<head>
|
|
<head>
|
|
@@ -600,8 +605,8 @@ function sendBackorderEmails($reservation) {
|
|
|
<p>Eine neue Nachbestellung wurde erstellt:</p>
|
|
<p>Eine neue Nachbestellung wurde erstellt:</p>
|
|
|
|
|
|
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px;">
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px;">
|
|
|
- <h3 style="margin-top: 0;">Abholcode:</h3>
|
|
|
|
|
- <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['code']) . '</h2>
|
|
|
|
|
|
|
+ <h3 style="margin-top: 0;">Bestellnummer:</h3>
|
|
|
|
|
+ <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['id']) . '</h2>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Kundendaten:</h3>
|
|
<h3>Kundendaten:</h3>
|
|
@@ -609,7 +614,7 @@ function sendBackorderEmails($reservation) {
|
|
|
<p><strong>E-Mail:</strong> ' . htmlspecialchars($reservation['customer_email']) . '</p>
|
|
<p><strong>E-Mail:</strong> ' . htmlspecialchars($reservation['customer_email']) . '</p>
|
|
|
|
|
|
|
|
<h3>Nachbestellungsdetails:</h3>
|
|
<h3>Nachbestellungsdetails:</h3>
|
|
|
- <p><strong>Nachbestellungsnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
|
|
|
|
+ <p><strong>Bestellnummer:</strong> ' . htmlspecialchars($reservation['id']) . '</p>
|
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
<p><strong>Erstellt am:</strong> ' . formatDate($reservation['created']) . '</p>
|
|
|
|
|
|
|
|
<h3>Nachbestellte Artikel:</h3>
|
|
<h3>Nachbestellte Artikel:</h3>
|
|
@@ -653,14 +658,14 @@ function sendBackorderAvailableEmail($reservation) {
|
|
|
<p>Ihre komplette Nachbestellung ist jetzt zur Abholung bereit.</p>
|
|
<p>Ihre komplette Nachbestellung ist jetzt zur Abholung bereit.</p>
|
|
|
|
|
|
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
<div style="background: #28292a; border: 2px solid #cac300; padding: 1.5rem; margin: 1.5rem 0; border-radius: 8px; text-align: center;">
|
|
|
- <h3 style="margin-top: 0; color: #f5f7fb;">Ihr Abholcode:</h3>
|
|
|
|
|
- <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['code']) . '</h2>
|
|
|
|
|
|
|
+ <h3 style="margin-top: 0; color: #f5f7fb;">Ihre Bestellnummer:</h3>
|
|
|
|
|
+ <h2 style="font-size: 2rem; letter-spacing: 0.2rem; color: #cac300; font-family: monospace;">' . htmlspecialchars($reservation['id']) . '</h2>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<h3>Bereitliegende Artikel:</h3>
|
|
<h3>Bereitliegende Artikel:</h3>
|
|
|
' . $itemsHtml . '
|
|
' . $itemsHtml . '
|
|
|
|
|
|
|
|
- <p>Bitte bringen Sie den Abholcode zur Abholung mit.</p>
|
|
|
|
|
|
|
+ <p>Bitte nennen Sie die Bestellnummer bei der Abholung.</p>
|
|
|
|
|
|
|
|
<p>Mit freundlichen Grüßen<br>' . SITE_NAME . '</p>
|
|
<p>Mit freundlichen Grüßen<br>' . SITE_NAME . '</p>
|
|
|
</div>
|
|
</div>
|