Example #1
0
 /**
  * Assign all taxes to reservation
  * 
  * @param RM_Reservation_Row $reservation
  * @param RM_Reservation_Details_Row $detailRow
  * @return bool
  */
 function assign(RM_Reservation_Details $detail, RM_Reservation_Details_Row $detailRow)
 {
     $detailsPrice = $detail->getTotal();
     $summaryModel = new RM_ReservationSummary();
     $summaryRows = $summaryModel->fetchByReservationDetail($detailRow);
     foreach ($summaryRows as $summaryRow) {
         if ($summaryRow->type !== self::SUMMARY_TYPE) {
             $detailsPrice += $summaryRow->total_amount;
         }
     }
     $model = new RM_Taxes();
     $taxes = $model->getByUnit($detail->getUnit());
     foreach ($taxes as $tax) {
         $summaryModel->insert(array('row_id' => $tax->id, 'type' => self::SUMMARY_TYPE, 'reservation_id' => null, 'reservation_detail_id' => $detailRow->id, 'total_amount' => $tax->calculate($detailsPrice, $detail), 'name' => $tax->getName(RM_Environment::getInstance()->getLocale())));
     }
 }
Example #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);
 }
Example #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;
 }
Example #4
0
 /**
  * Add additional information for reservation process
  *
  * @param RM_Reservation_Details $details
  * @return RM_Reservation_Manager
  */
 public function addDetails(RM_Reservation_Details $details)
 {
     $selectedUnit = $details->getUnit();
     //don't use getUnit as this returns the saved unit
     $id = $selectedUnit->id;
     $this->_details[$id] = $details;
     $this->save();
     return $this;
 }