$quote['label'] = (string)($promo['label'] ?: $code . ' coupon'); $quote['source'] = 'Catalog promo database'; $discountType = strtolower((string)($promo['discountType'] ?? 'percent')); $defaultRate = max(0.0, min(100.0, (float)($promo['discountPercent'] ?? 0))) / 100.0; if ((int)($promo['active'] ?? 0) !== 1) { $quote['note'] = $code . ' coupon is inactive and will be reviewed manually.'; return $quote; } if (empty($promo['windowApplies'])) { $quote['note'] = $code . ' coupon is outside its valid event-date window and will be reviewed manually.'; return $quote; } $discountTotal = 0.0; $chargedSubtotal = 0.0; $weightedRateTotal = 0.0; for ($i = 0; $i < $rentalDays; $i++) { $day = $eventDate ? (new DateTimeImmutable($eventDate, new DateTimeZone('America/Chicago')))->modify('+' . $i . ' days') : null; $rate = $defaultRate; if ($discountType === 'weekday_weekend' && $day) { $dow = (int)$day->format('N'); $pct = ($dow >= 1 && $dow <= 4) ? ($promo['weekdayPercent'] ?? $promo['discountPercent'] ?? 0) : ($promo['weekendPercent'] ?? $promo['discountPercent'] ?? 0); $rate = max(0.0, min(100.0, (float)$pct)) / 100.0; } $dayMultiplier = $i === 0 ? 1.0 : 0.5; $daySubtotal = round($baseRentalSubtotal * $dayMultiplier, 2); $dayDiscount = round($daySubtotal * $rate, 2); $chargedSubtotal += $daySubtotal; $weightedRateTotal += $rate * $daySubtotal; $discountTotal += $dayDiscount; $quote['dailyBreakdown'][] = [ 'date' => $day ? $day->format('Y-m-d') : '', 'rate' => $rate, 'rentalMultiplier' => $dayMultiplier, 'rentalSubtotal' => $daySubtotal, 'discountAmount' => $dayDiscount, ]; } $quote['rate'] = $chargedSubtotal > 0 ? round($weightedRateTotal / $chargedSubtotal, 4) : round($defaultRate, 4); if ($quote['rate'] <= 0) { $quote['note'] = $code . ' coupon is recognized but has no usable discount saved.'; return $quote; } $quote['discountAmount'] = round($discountTotal, 2); $quote['isApplied'] = $quote['discountAmount'] > 0; $displayRate = rtrim(rtrim(number_format($quote['rate'] * 100, 2), '0'), '.'); $quote['note'] = (string)($promo['customerNote'] ?? '') ?: ($code . ' coupon applied: ' . $displayRate . '% off rental items. Only rental items are discounted; delivery and tax are not discounted.'); /* DETAIL_PROVIDER_META_V004: provider info is part of the product info grid and shows DB provider name only. Logo remains floating on the image. */ .metaBox.providerMetaBox{ display:flex!important; align-items:center!important; gap:10px!important; min-width:0!important; } .metaBox.providerMetaBox .providerMetaLogo{ width:34px!important; height:34px!important; flex:0 0 34px!important; border-radius:999px!important; object-fit:cover!important; background:rgba(255,255,255,.72)!important; border:1px solid rgba(255,255,255,.66)!important; box-shadow:0 8px 18px rgba(15,23,42,.12)!important; } .metaBox.providerMetaBox .providerMetaText{ min-width:0!important; } .metaBox.providerMetaBox .providerMetaText strong{ overflow:hidden!important; text-overflow:ellipsis!important; white-space:nowrap!important; } @media (prefers-color-scheme:dark){ .metaBox.providerMetaBox .providerMetaLogo{ background:rgba(15,23,42,.58)!important; border-color:rgba(148,163,184,.26)!important; } }