Ejemplo n.º 1
0
 /**
  * Returns total price for reservation with only options that are
  * connected to reservation itself. It could be only '-' if there is only a discount for example
  *
  * @return float
  */
 private function _getTotalPrice()
 {
     $total = 0;
     $summaryModel = new RM_ReservationSummary();
     $summaryRows = $summaryModel->fetchByReservation($this);
     foreach ($summaryRows as $row) {
         $total += $row->total_amount;
     }
     return $total;
 }
Ejemplo n.º 2
0
 /**
  * Edit Reservation sets up the enviroment for editing a reservation and loads data.
  *
  * Creates temporary entries for the temp reservation data, loads the form
  * configuration, data for users, calendar information. This method is the PHP
  * code behind the edit.js function. All initial data loaded onto this form
  * is controlled by this method.
  *
  * @param   request id the reservation id.
  * @return 	json    json array information.
  */
 public function editJsonAction()
 {
     $reservationID = $this->_getParam('id', null);
     if ($reservationID == null) {
         return array('data' => array('success' => false));
     }
     $reservationModel = new RM_Reservations();
     $reservation = $reservationModel->find($reservationID)->current();
     if ($reservation == null) {
         return array('data' => array('success' => false));
     }
     $details = $reservation->findReservationDetails();
     $billing = new RM_Billing();
     $reservationDetailsModel = new RM_ReservationDetails();
     $jsonDetails = array();
     $savedpriceData = array();
     $config = new RM_Config();
     $summaryModel = new RM_ReservationSummary();
     foreach ($details as $detail) {
         $unit = $detail->findUnit();
         if ($unit == null) {
             continue;
         }
         $priceSystem = RM_Prices_Manager::getInstance()->getRealPriceSystem($unit);
         $showTimeFields = (int) $priceSystem->getShowTime($unit);
         $unitReservationDetails = $reservationDetailsModel->findByUnit($unit, array($reservation));
         $jsonDisabledPeriods = array();
         // TODO: Need to check if this required
         // not sure why we need this now...
         // each reservation is 1 reservation per unit
         // so why do we need a loop to iterate all reservations.
         //valentin: we need to show every reserved period for this unit by other reservations
         foreach ($unitReservationDetails as $unitReservationDetail) {
             $jsonDisabledPeriods[] = "{\n                    start_date: '" . $unitReservationDetail->getStartDatetime($priceSystem->getDateformat(true)) . "',\n                    end_date: '" . $unitReservationDetail->getEndDatetime($priceSystem->getDateformat(true)) . "',\n                }";
         }
         // other information that is price system specific ie. board_type
         $otherInfo = $priceSystem->getOtherInfo();
         foreach ($otherInfo as $otherName) {
             $othersJson .= $otherName . ": '" . $detail->{$otherName} . "',";
         }
         // get the other systems
         $otherSystems = RM_Environment::getInstance()->getOthersSystems();
         foreach ($otherSystems as $otherSystem) {
             $oSystems[] = "'" . $otherSystem->name . "'";
         }
         $jsonDetails[] = "{\n                unit: {\n                    id: '" . $unit->getId() . "',\n                    name: '" . addslashes($unit->name) . "',\n                },\n                reserved_period: {\n                    start_date: '" . $detail->getStartDatetime($priceSystem->getDateformat(true)) . "',\n                    end_date: '" . $detail->getEndDatetime($priceSystem->getDateformat(true)) . "'\n                },\n                persons: {\n                    adults: '" . $detail->adults . "',\n                    children: '" . $detail->children . "',\n                    infants: '" . $detail->infants . "',\n                },\n                othersystems: [" . implode(",", $oSystems) . "],\n                pricesystem: '" . $priceSystem->name . "',\n                showtime: " . $showTimeFields . ",\n                " . $othersJson . "\n                blocked_periods: [" . implode(',', $jsonDisabledPeriods) . "]\n              }";
         $config = new RM_Config();
         $currencySymbol = $config->getValue('rm_config_currency_symbol');
         $summaryRows = $summaryModel->fetchByReservationDetail($detail)->toArray();
         for ($i = 0; $i < count($summaryRows); $i++) {
             $summaryRows[$i]['total_amount'] = $currencySymbol . RM_Environment::getInstance()->roundPrice($summaryRows[$i]['total_amount']);
         }
         $savedpriceData[] = "{\n                unit: {\n                    id: '" . $unit->getId() . "',\n                    name: '" . addslashes($unit->name) . "',\n                },\n                total_sub: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($detail->total_price) . "',\n                reserved_period: {\n                    start_date: '" . $detail->getStartDatetime() . "',\n                    end_date: '" . $detail->getEndDatetime() . "'\n                },\n                summary_rows: " . Zend_Json::encode($summaryRows) . ",\n                showtime: " . $showTimeFields . "\n             }\n             ";
     }
     $payments = $billing->getPayments($reservation);
     $paymentsData = array();
     foreach ($payments as $payment) {
         $paymentsData[] = "{\n                date: '" . $payment->transaction_date . "',\n                provider: '" . $payment->provider . "',\n                transactionid: '" . $payment->transaction_id . "',\n                status: '" . $payment->status . "',\n                total_paid: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($payment->total_paid) . "'\n            }";
     }
     $reservationConfigModel = new RM_ReservationConfig();
     $fields = $reservationConfigModel->getAdminEditFields();
     $jsonFields = array();
     foreach ($fields as $field) {
         $jsonFields[] = $field->admin_view_edit;
     }
     $reservationSummaryRows = $summaryModel->fetchByReservation($reservation)->toArray();
     for ($i = 0; $i < count($reservationSummaryRows); $i++) {
         $reservationSummaryRows[$i]['total_amount'] = $currencySymbol . RM_Environment::getInstance()->roundPrice($reservationSummaryRows[$i]['total_amount']);
     }
     // reservation price information
     $user = $reservation->findParentUsers();
     $json = "{\n            data : " . Zend_Json::encode($reservation->toArray()) . ",\n            fields : [" . implode(',', $jsonFields) . "],\n            user: {\n                id : '" . $user->id . "',\n                last_name : '" . addslashes($user->last_name) . "',\n                first_name : '" . addslashes($user->first_name) . "',\n            },\n            details: [\n                " . implode(',', $jsonDetails) . "\n            ],\n            pricedata: {\n                prices: [" . implode(',', $savedpriceData) . "],\n                reservation_summary_rows: " . Zend_Json::encode($reservationSummaryRows) . ",\n                reservationTotal: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($reservation->getTotalPrice()) . "'\n            },\n            paymentdata: {\n                payments: [" . implode(',', $paymentsData) . "]\n            }\n        }";
     // set the read marker
     $reservation->is_read = 1;
     $reservation->save();
     return array('data' => $json, 'encoded' => true);
 }