Example #1
0
 public function isApplicable($amount, $email, $nightCount, &$message)
 {
     global $logger;
     $logger->LogDebug(__METHOD__ . " Checking if promo code is applicable to amount: {$amount}; email: {$email}; night count: {$nightCount} ...");
     $currentDate = new Date();
     if (!$this->isValid()) {
         $logger->LogError("Object is invalid!");
         $message = $this->errors[0];
         return false;
     }
     // Check if coupon has been used
     if (!$this->isReusable) {
         $logger->LogDebug("Promo is not reusable. Checking if it has been used already ...");
         $bookings = Booking::fetchForPromoCode($this->promoCode);
         if (count($bookings) > 0) {
             $logger->LogDebug("Promo has been used on booking id: " . $bookings[0]->id);
             $message = BOOKING_DETAILS_COUPON_USED;
             return false;
         }
     }
     // Not enough purchases
     if ($this->minAmount > 0 && floatval($amount) < $this->minAmount) {
         $logger->LogDebug("Promo has a minumum amount of {$this->minAmount} so it is not applicable!");
         $message = BOOKING_DETAILS_COUPON_MIN_AMT;
         return false;
     }
     // Expired code
     if ($this->expirationDate != null && $currentDate->compareTo($this->expirationDate) == 1) {
         $logger->LogDebug("Current date is: {$currentDate->format}('m/d/Y') so promo has expired!");
         $message = BOOKING_DETAILS_COUPON_EXPIRED;
         return false;
     }
     // Minimun nights
     if ($this->minNights > 0 && $nightCount < $this->minNights) {
         $logger->LogDebug("Promo has a minumum nights of {$this->minNights} so it is not applicable!");
         $message = BOOKING_DETAILS_COUPON_MIN_NIGHTS_PART_1 . " " . $this->minNights . " " . BOOKING_DETAILS_COUPON_MIN_NIGHTS_PART_2;
         return false;
     }
     // Must be existing customer
     if ($this->category == 1) {
         $logger->LogDebug("Promo must be used on an existing customer.");
         $client = Client::fetchFromDbForEmail($email);
         if (client == null) {
             $logger->LogDebug("There is no customer with email: {$email} in existing customers. Promo is not applicable!");
             $message = BOOKING_DETAILS_COUPON_WRONG_CUSTOMER;
             return false;
         }
     } else {
         if ($this->category == 2 && $this->customerEmail != null && strlen(trim($this->customerEmail)) > 0 && trim(strtolower($this->customerEmail)) != trim(strtolower($email))) {
             $logger->LogDebug("Promo code must be used on a speciifc customer and promo customer: {$this->customerEmail} and booking customer: {$email} do not match!");
             $message = BOOKING_DETAILS_COUPON_WRONG_CUSTOMER;
             return false;
         } else {
             if ($this->category == 3 && $this->customerEmail != null && strlen(trim($this->customerEmail)) > 0) {
                 $logger->LogDebug("Promo must be used on a new customer.");
                 $bookings = Booking::fetchForClientEmail($email);
                 $client = Client::fetchFromDbForEmail(trim(strtolower($email)));
                 if (count($bookings) > 0) {
                     $logger->LogDebug("Customer: {$email} already has " . count($bookings) . " booking(s) so promo is not applicable!");
                     $message = BOOKING_DETAILS_COUPON_ONLY_NEW_CUSTOMER;
                     return false;
                 }
             }
         }
     }
     $logger->LogDebug("Promo is applicable!");
     return true;
 }
Example #2
0
    $_SESSION['errors'][] = "Session object was not set. Try the booking process from the start";
    header('Location: error.php');
}
// Get booking details from session
$bookingDetails = unserialize($_SESSION['bookingDetailsAdmin']);
// Get Client
$client = Client::fetchFromParameters($_POST);
if (!$client->isValid()) {
    $logger->LogError("Client is not valid!");
    $logger->LogError($client->errors);
    $_SESSION['errors'] = $client->errors;
    header('Location: booking-step4.php');
}
$bookingDetails->client = $client;
// Update client data
$client = Client::fetchFromDbForEmail($bookingDetails->client->email);
if ($client != null) {
    $bookingDetails->client->id = $client->id;
}
if (!$bookingDetails->client->save()) {
    $logger->LogError("Saving client failed!");
    $logger->LogError($client->errors);
    $_SESSION['errors'] = $bookingDetails->client->errors;
    header('Location: error.php');
}
// Validate booking info
if (!$bookingDetails->isValid()) {
    $logger->LogError("BookingDetails are not valid!");
    $logger->LogError($bookingDetails->errors);
    $_SESSION['errors'] = $bookingDetails->errors;
    header('Location: error.php');