Exemplo n.º 1
0
 /**
  * IMPORTANT! This method only checked internal rule matched,
  * to get all discount for a unit (and global) @see RM_Discounts::getByUnit
  *
  * @param RM_Reservation_Details $detail
  * @return void
  */
 public function isMatched(RM_Reservation_Details $detail)
 {
     //if type is amount we need to check that reservation is in dates
     if ($this->type == 'amount') {
         $discountPeriod = $this->getPeriod();
         $startDate = $detail->getPeriod()->getStart();
         if ($startDate->compare($discountPeriod->getStart()) >= 0 && $startDate->compare($discountPeriod->getEnd()) <= 0) {
             return true;
         }
     }
     if ($this->type == 'percentage') {
         if ($this->getPeriod()->getIntersection($detail->getPeriod()) !== null) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Calculate
  *
  * @param RM_Discounts_Row $row
  * @param float $amount
  * @return float
  */
 public function calculate(RM_Reservation_Details $detail)
 {
     $discountPeriod = $this->_discount->getPeriod();
     $totalDiscount = 0;
     $discountPercentage = $this->_discount->amount;
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     try {
         $priceDays = $priceSystem->getTotalUnitPrice(new RM_Prices_Information($detail->getUnit(), $detail->getPeriod(), $detail->getPersons()), true);
     } catch (RM_Exception $e) {
         $priceDays = 0;
     }
     foreach ($priceDays as $day) {
         if ($discountPeriod->isInternal($day['step'])) {
             $discountedPrice = $day['price'];
             $totalDiscount += $day['price'] / 100 * $discountPercentage;
         }
     }
     return RM_Environment::getInstance()->roundPrice($totalDiscount);
 }
Exemplo n.º 3
0
 /**
  * Validate extras selection for the user GUI
  *
  * @param array $data in format [extras system name][unit id][extra id] = user selected value for the extra
  * @return bool
  */
 public function applySelection(Zend_Controller_Request_Abstract $request, RM_Reservation_Details $detail)
 {
     $data = $request->getParam('rm_extras', array());
     if (is_array($data) == false) {
         return false;
     }
     if (count($data) == 0) {
         return $detail;
     }
     if (isset($data[$detail->getUnit()->id]) == false) {
         return $detail;
     }
     if (is_array($data[$detail->getUnit()->id]) == false) {
         return false;
     }
     if (count($data[$detail->getUnit()->id]) == 0) {
         return $detail;
     }
     // tax
     $taxSystem = RM_Environment::getInstance()->getTaxSystem();
     $taxes = $taxSystem->getAllTaxes($detail->getUnit());
     $model = new RM_Extras();
     $extras = array();
     foreach ($data[$detail->getUnit()->id] as $extraID => $value) {
         $extra = $model->find($extraID)->current();
         if ($extra == null) {
             continue;
         }
         if ($extra->isBelongTo($detail->getUnit()) == false) {
             continue;
         }
         if (($value > $extra->max || $value < $extra->min) && $value != 0) {
             continue;
         }
         // calculate the tax due on the extra...
         $extraTotal = $extra->calculateBy($detail->getTotal(), $detail->getPeriod()->getSeconds());
         $taxTotal = 0;
         foreach ($taxes as $tax) {
             $taxTotal = $taxTotal + $tax->calculate($extraTotal, $detail);
         }
         $extraObject = new RM_Extras_Object($extra, $value * $extraTotal, $value, $value * $taxTotal);
         $extras[] = $extraObject;
     }
     $detail->addExtras($extras);
     return $detail;
 }