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
 /**
  * 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;
 }
Example #3
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 #4
0
 /**
  * Assign extras to reservation
  *
  * @param RM_Reservation_Details $detail
  * @param RM_Reservation_Details_Row $detailRow
  * @return void
  */
 public function assign(RM_Reservation_Details $detail, RM_Reservation_Details_Row $detailRow)
 {
     $extras = $detail->getExtras();
     foreach ($extras as $extra) {
         if ($extra instanceof RM_Extras_Object) {
             $summaryModel = new RM_ReservationSummary();
             $summaryModel->insert(array('row_id' => $extra->getID(), 'type' => self::SUMMARY_TYPE, 'reservation_detail_id' => $detailRow->id, 'value' => $extra->getValue(), 'total_amount' => $extra->getPrice(), 'name' => $extra->getName()));
             // insert the extra tax
             $summaryModel->insert(array('row_id' => $extra->getID(), 'type' => self::SUMMARY_TYPE_TAX, 'reservation_detail_id' => $detailRow->id, 'value' => $extra->getValue(), 'total_amount' => $extra->getTax(), 'name' => "Extras Tax"));
         }
     }
 }
Example #5
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;
 }