mirror of
https://github.com/myronblair/parkerslingshot
synced 2026-06-30 17:50:22 -05:00
Fix multi-day full-day pricing: add days selector, multiply amount by rental days
This commit is contained in:
+12
-6
@@ -35,9 +35,13 @@ if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date) || strtotime($date) < strtotime(
|
||||
echo json_encode(['success'=>false,'error'=>'Invalid or past date.']); exit;
|
||||
}
|
||||
|
||||
$pkg = PACKAGES[$package];
|
||||
$pkg = PACKAGES[$package];
|
||||
$rentalDays = ($package === 'full-day') ? max(1, min(3, (int)($input['rental_days'] ?? 1))) : 1;
|
||||
$rentalDate = $date;
|
||||
$endDate = date('Y-m-d', strtotime($date . ' +' . $pkg['days'] . ' days'));
|
||||
$endDate = ($package === 'full-day')
|
||||
? date('Y-m-d', strtotime($date . ' +' . ($rentalDays - 1) . ' days'))
|
||||
: date('Y-m-d', strtotime($date . ' +' . $pkg['days'] . ' days'));
|
||||
$totalAmount = ($package === 'full-day') ? $pkg['amount'] * $rentalDays : $pkg['amount'];
|
||||
|
||||
// Check availability
|
||||
$conflict = db()->prepare(
|
||||
@@ -57,10 +61,12 @@ if ($blockedCheck->fetch()) {
|
||||
|
||||
$ref = generateRef();
|
||||
$dateLabel = date('F j, Y', strtotime($rentalDate));
|
||||
$pkgLabel = $pkg['label'];
|
||||
$amountLabel = '$' . number_format($pkg['amount'], 2);
|
||||
$pkgLabel = ($package === 'full-day' && $rentalDays > 1)
|
||||
? $pkg['label'] . ' × ' . $rentalDays . ' days'
|
||||
: $pkg['label'];
|
||||
$amountLabel = '$' . number_format($totalAmount, 2);
|
||||
$depositLabel = '$' . number_format(DEPOSIT_AMOUNT, 2);
|
||||
$balance = $pkg['amount'] - DEPOSIT_AMOUNT;
|
||||
$balance = $totalAmount - DEPOSIT_AMOUNT;
|
||||
$balanceLabel = '$' . number_format($balance, 2);
|
||||
|
||||
// ── Square: create customer + card on file + deposit hold ─────────────────────
|
||||
@@ -143,7 +149,7 @@ $stmt = db()->prepare(
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
);
|
||||
$stmt->execute([
|
||||
$ref, $name, $email, $phone, $package, $rentalDate, $endDate, $pkg['amount'], $message,
|
||||
$ref, $name, $email, $phone, $package, $rentalDate, $endDate, $totalAmount, $message,
|
||||
$sqCustomerId, $sqCardId, $sqCardLast4, $sqCardBrand,
|
||||
$sqPaymentId, $sqPaymentStatus,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user