public static function fetchFromDbForDate($date) { MonthlyDiscountDeposit::$staticErrors = array(); if (!$date instanceof Date) { MonthlyDiscountDeposit::setStaticError("Date is not an instance of date"); return null; } return MonthlyDiscountDeposit::fetchFromDb(intval($date->format("m"))); }
if (!$discountDeposit->save()) { array_push($errors, $discountDeposit->errors); } } $enabled = isset($_POST['conf_enabled_deposit']) && intval($_POST['conf_enabled_deposit']) == 1 ? 1 : 0; $systemConfiguration->setIsMonthlyDepositSchemeEnabled($enabled); $enabled = isset($_POST['conf_enabled_discount']) && intval($_POST['conf_enabled_discount']) == 1 ? 1 : 0; $systemConfiguration->setIsMonthlyDiscountSchemeEnabled($enabled); if (!$systemConfiguration->save(true)) { $errors = array_merge($errors, $systemConfiguration->errors); } if (sizeof($errors) == 0) { $message = "Values were succesfully updated."; } } $discountsDeposits = MonthlyDiscountDeposit::fetchAllFromDb(); include "header.php"; ?> </td> </tr> <tr> <td valign="top" > <?php if (sizeof($errors) > 0) { echo ' <table width="100%">' . "\n"; foreach ($errors as $error) { echo ' <tr><td class="TitleBlue11pt" style="color: red; font-weight: bold;">' . htmlentities($error) . '</td></tr>' . "\n"; } echo ' </table>' . "\n"; } else {
public function calculatePriceDetails($languageCode) { $this->errors = array(); $priceDetails = new PriceDetails(); global $systemConfiguration; // Get room and extra bed prices $roomPriceDetails = $this->room->getRoomAndBedPrice($this->searchCriteria->checkInDate, $this->searchCriteria->checkOutDate); if ($roomPriceDetails == null) { array_push($this->errors, $this->room->errors); return false; } else { if (sizeof($roomPriceDetails) != 2) { $this->setError("Invalid number of array elements returned: " . sizeof($roomPriceDetails)); return false; } } $priceDetails->roomPrice = floatval($roomPriceDetails[0]); $priceDetails->subtotalBeforeDiscounts = $priceDetails->roomPrice; if ($this->extraBedRequested) { $priceDetails->extraBedPrice = floatval($roomPriceDetails[1]); $priceDetails->subtotalBeforeDiscounts += $priceDetails->extraBedPrice; } // Add extra services foreach ($this->extraServices as $extraServiceDetails) { if (!$extraServiceDetails[0] instanceof ExtraService) { continue; } $extraService = $extraServiceDetails[0]; $quantity = intval($extraServiceDetails[1]); $extraServicePrice = floatval($extraServiceDetails[2]); //$priceDetails->extraServicesPrice[] = array( 0 => $extraService->getName($languageCode), 1 => $quantity, 2 => $extraServicePrice); $priceDetails->subtotalBeforeDiscounts += $extraServicePrice; } $priceDetails->extraServicesDetail = $this->extraServices; // Initialize subototal after discounts $priceDetails->subtotalAfterDiscounts = $priceDetails->subtotalBeforeDiscounts; // Get monthly discount/deposit details $monthlyDiscountDeposit = null; if ($systemConfiguration->isMonthlyDiscountSchemeEnabled() || $systemConfiguration->isMonthlyDepositSchemeEnabled()) { $monthlyDiscountDeposit = MonthlyDiscountDeposit::fetchFromDbForDate($this->searchCriteria->checkInDate); if ($monthlyDiscountDeposit == null) { array_push($this->errors, MonthlyDiscountDeposit::$staticErrors); return false; } } // Apply monthly discounts if ($systemConfiguration->isMonthlyDiscountSchemeEnabled() && $monthlyDiscountDeposit->discountPercent > 0) { $priceDetails->monthlyDiscountPercent = $monthlyDiscountDeposit->discountPercent; $priceDetails->monthlyDiscount = round(min(floatval($monthlyDiscountDeposit->discountPercent * $priceDetails->subtotalAfterDiscounts / 100), $priceDetails->subtotalAfterDiscounts), 2); $priceDetails->subtotalAfterDiscounts -= $priceDetails->monthlyDiscount; } // Apply promo discounts if ($this->promoCode != null) { $priceDetails->promoCode = $this->promoCode->promoCode; $priceDetails->promoDiscount = $this->promoCode->getDiscount($priceDetails->subtotalAfterDiscounts); $priceDetails->subtotalAfterDiscounts -= $priceDetails->promoDiscount; } // Initialize grand total $priceDetails->grandTotal = $priceDetails->subtotalAfterDiscounts; // Apply tax if ($systemConfiguration->getTaxRate() > 0) { $priceDetails->taxRate = $systemConfiguration->getTaxRate(); $priceDetails->taxAmount = round($priceDetails->subtotalAfterDiscounts * $priceDetails->taxRate / 100, 2); $priceDetails->grandTotal = $priceDetails->subtotalAfterDiscounts + $priceDetails->taxAmount; } // Apply monthly deposit $priceDetails->totalDue = $priceDetails->grandTotal; if ($systemConfiguration->isMonthlyDepositSchemeEnabled() && $monthlyDiscountDeposit->depositPercent > 0) { $priceDetails->monthlyDepositPercent = $monthlyDiscountDeposit->depositPercent; $priceDetails->totalDue = round(floatval($monthlyDiscountDeposit->depositPercent * $priceDetails->grandTotal / 100), 2); } $this->priceDetails = $priceDetails; }