예제 #1
0
 /**
  * The only one method to return the instance of this class, 'cause constructor is private
  *
  * @return RM_Prices_Manager
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function configJsonAction()
 {
     $rmUnitTypes = new RM_UnitTypes();
     $language = RM_Environment::getInstance()->getLocale();
     $unittypes = $rmUnitTypes->getAll();
     $type = array();
     foreach ($unittypes as $unittype) {
         $type[] = array('id' => $unittype->id, 'name' => $unittype->{$language}, 'price' => $unittype->price);
     }
     $json = new stdClass();
     $json->unitTypes = $type;
     $systems = RM_Prices_Manager::getAllPriceSystems();
     $json->systems = array();
     foreach ($systems as $system) {
         $json->systems[] = array('value' => $system->name, 'text' => $system->getName(RM_Environment::getInstance()->getLocale()));
     }
     $module = new RM_Module_UnitTypeManager();
     $defaultUnitType = $module->getDefaultUnitType();
     $json->defaultUnitType = $defaultUnitType->id;
     return array('data' => $json, 'encoded' => false);
 }
예제 #3
0
 /**
  * Ruturn current enabled price system in application
  *
  * @return RM_Prices_Manager
  */
 public function getPriceSystem()
 {
     return RM_Prices_Manager::getInstance();
 }
예제 #4
0
 public function unitsJsonAction()
 {
     $unitModel = new RM_Units();
     $units = $unitModel->getAll(new RM_Unit_Search_Criteria());
     $unitsJson = array();
     foreach ($units as $unit) {
         $unitJson = new stdClass();
         $unitJson->Id = $unit->getId();
         $unitJson->Name = $unit->name;
         $unitJson->Color = $unit->color;
         $unitJson->ShowTime = (bool) RM_Prices_Manager::getInstance()->getRealPriceSystem($unit)->getShowTime($unit);
         $unitsJson[] = $unitJson;
     }
     return array('data' => $unitsJson);
 }
예제 #5
0
 public function listhtmlJsonAction()
 {
     $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));
     }
     $unitModel = new RM_Units();
     $reservationDetails = $reservation->getDetails();
     $reservationDetailsJson = array();
     foreach ($reservationDetails as $reservationDetail) {
         $unit = $reservationDetail->findUnit();
         $extrasModel = new RM_Extras();
         $extras = $extrasModel->getByUnit($unit);
         if ($extras->count() == 0) {
             continue;
         }
         $config = new RM_Config();
         $currencySymbol = $config->getValue('rm_config_currency_symbol');
         // tax
         $taxSystem = RM_Environment::getInstance()->getTaxSystem();
         $taxes = $taxSystem->getAllTaxes($unit);
         // we need to create a new reservation details object so that the tax can be calculated
         $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($reservationDetail->start_datetime)), new RM_Date(strtotime($reservationDetail->end_datetime)));
         $persons = new RM_Reservation_Persons(array("adults" => $reservationDetail->adults, "children" => $reservationDetail->children, "infants" => $reservationDetail->infants));
         $fullReservationDetails = new RM_Reservation_Details($unit, $periodObj, $persons, array());
         $summaryModel = new RM_ReservationSummary();
         $extrasJson = array();
         foreach ($extras as $extra) {
             // calculate the tax due on the extra...
             $extraSubTotal = $extra->calculate($reservationDetail);
             $taxTotal = 0;
             foreach ($taxes as $tax) {
                 $taxTotal = $taxTotal + $tax->calculate($extraSubTotal, $fullReservationDetails);
             }
             $extraSubTotal = $extraSubTotal + $taxTotal;
             $extraJson = new stdClass();
             $extraJson->id = $extra->id;
             $extraJson->name = $extra->getName(RM_Environment::getInstance()->getLocale());
             $extraJson->min = (int) $extra->min;
             $extraJson->max = (int) $extra->max;
             $extraJson->type = RM_Environment::getInstance()->getTranslation()->_('Admin.Extras.Type', ucfirst($extra->type));
             $extraJson->price = $currencySymbol . $extraSubTotal;
             $reservationDetailsExtra = $summaryModel->getByDetail($reservationDetail, RM_Module_Extras::SUMMARY_TYPE, $extra->id);
             if ($reservationDetailsExtra == null) {
                 $extraJson->saved_price = $currencySymbol . '0';
                 $extraJson->value = 0;
             } else {
                 $extraJson->saved_price = $currencySymbol . $reservationDetailsExtra->total_amount;
                 $extraJson->value = (int) $reservationDetailsExtra->value;
             }
             $extrasJson[] = $extraJson;
         }
         $unit = $unitModel->get($reservationDetail->unit_id);
         if ($unit == null) {
             $unitName = "DELETED";
         } else {
             $unitName = $unit->name;
         }
         $priceSystem = RM_Prices_Manager::getInstance()->getRealPriceSystem($unit);
         $reservationDetailJson = new stdClass();
         $reservationDetailJson->id = $reservationDetail->id;
         $reservationDetailJson->extras = $extrasJson;
         $reservationDetailJson->unit_id = $reservationDetail->unit_id;
         $reservationDetailJson->unit_name = $unitName;
         $reservationDetailJson->start = $reservationDetail->getStartDatetime($priceSystem->getDateformat(true));
         $reservationDetailJson->end = $reservationDetail->getEndDatetime($priceSystem->getDateformat(true));
         $reservationDetailJson->subtotal = $reservationDetail->total_price;
         $reservationDetailsJson[] = $reservationDetailJson;
     }
     $json = new stdClass();
     $json->details = $reservationDetailsJson;
     return array('data' => $json);
 }
예제 #6
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);
 }
예제 #7
0
파일: Units.php 프로젝트: laiello/resmania
 /**
  * Returns all unit objects by it's type
  *
  * @param object    $criteria this object contains the specification for the
  * search.
  * @return Zend_Db_Table_Rowset All units objects
  */
 public function getAll(RM_Unit_Search_Criteria $criteria)
 {
     $fieldsNames = array();
     $fieldsNames[] = 'rm_units.*';
     $languageFieldsNames = array();
     $languageFieldsNames[] = 'rm_unit_language_details.*';
     if ($criteria->offset === null) {
         $criteria->offset = 0;
     }
     $sql = "\r\n            SELECT\r\n                " . implode(',', $fieldsNames);
     if (count($languageFieldsNames) > 0) {
         $sql .= ", " . implode(',', $languageFieldsNames);
     }
     if (!$criteria->language) {
         $criteria->language = RM_Environment::getInstance()->getLocale();
     }
     $sql .= "\r\n            FROM\r\n                rm_units\r\n            INNER JOIN\r\n                rm_unit_language_details ON\r\n                rm_units.id = rm_unit_language_details.unit_id";
     $sql .= "\r\n            AND rm_unit_language_details.iso = '{$criteria->language}'\r\n                WHERE 1=1 ";
     if ($criteria->type) {
         $sql .= " AND type_id = '" . $criteria->type->id . "' ";
     }
     // this gets the units that are unavailable so these are excluded from the results
     if ($criteria->start_datetime && $criteria->end_datetime) {
         $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
         if ($criteria->flexible) {
             //My dates are flexible: every unit with at least one day available should we shown
             $availableUnitIDs = $this->getFlexibleAvailable($reservationPeriod);
             if (count($availableUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $availableUnitIDs) . ")\r\n                    ";
             }
         } else {
             $reservedUnits = $this->getReservedUnits($reservationPeriod)->toArray();
             $unitsWithAvailbilityCheckDisabled = RM_Environment::getInstance()->getPriceSystem()->getUnitWithAvailabiltyCheckDisabled();
             if (count($reservedUnits) > 0) {
                 $reservedUnits = array_diff($reservedUnits, $unitsWithAvailbilityCheckDisabled);
             }
             if (count($reservedUnits) > 0) {
                 $reservedUnitIDs = array();
                 foreach ($reservedUnits as $unit) {
                     if ($unit['id']) {
                         $reservedUnitIDs[] = $unit['id'];
                     }
                 }
                 $reservedUnitsCSV = implode(',', $reservedUnitIDs);
                 if ($reservedUnitsCSV != "," && $reservedUnitsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $reservedUnitsCSV . ")\r\n                        ";
                 }
             }
             //we need to check min period length
             $manager = RM_Prices_Manager::getInstance();
             $minPeriodNotUnitIDs = $manager->getByMinPeriod($reservationPeriod);
             if (count($minPeriodNotUnitIDs) > 0) {
                 $minPeriodNotUnitIDsCSV = implode(',', $minPeriodNotUnitIDs);
                 if ($minPeriodNotUnitIDsCSV != "," && $minPeriodNotUnitIDsCSV != "") {
                     $sql .= "\r\n                            AND rm_units.id NOT IN (" . $minPeriodNotUnitIDsCSV . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->image == 1) {
         $unitIDsWithImages = $this->getWithImages();
         if (count($unitIDsWithImages) == 0) {
             $sql .= " AND 1=0 ";
             //This will returns 0 rows
             return $this->_getBySQL($sql);
         } else {
             $sql .= "\r\n                    AND rm_units.id IN (" . implode(',', $unitIDsWithImages) . ")\r\n                ";
         }
     }
     //3. prices: from - to
     if ((int) $criteria->prices_from != 0 || (int) $criteria->prices_to != 99999999) {
         if ($criteria->prices_from || $criteria->prices_to) {
             if ($criteria->start_datetime && $criteria->end_datetime) {
                 $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime)));
             } else {
                 $reservationPeriod = null;
             }
             $priceRangeUnitIDs = RM_Environment::getInstance()->getPriceSystem()->getByPriceRange($criteria->prices_from, $criteria->prices_to, $reservationPeriod);
             if (count($priceRangeUnitIDs) == 0) {
                 $sql .= " AND 1=0 ";
                 //This will returns 0 rows
                 return $this->_getBySQL($sql);
             } else {
                 $sql .= "\r\n                        AND rm_units.id IN (" . implode(',', $priceRangeUnitIDs) . ")\r\n                    ";
             }
         }
     }
     //4. check all plugins and modules to extend advanced search
     $model = new RM_Modules();
     $modules = $model->getAllEnabled();
     foreach ($modules as $module) {
         if ($module instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $module->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $module->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     $pluginModel = new RM_Plugins();
     $plugins = $pluginModel->getAllEnabled();
     foreach ($plugins as $plugin) {
         if ($plugin instanceof RM_Search_Advanced_Interface) {
             $unitIDs = $plugin->getAdvancedSearchUnitIDs($criteria);
             if ($unitIDs !== false) {
                 if (count($unitIDs) == 0) {
                     $sql .= " AND 1=0 ";
                     //This will returns 0 rows
                     return $this->_getBySQL($sql);
                 } elseif (count($unitIDs) > 0) {
                     $sql .= "\r\n                            -- added by modules: " . $plugin->name . "\r\n                            AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n                        ";
                 }
             }
         }
     }
     if ($criteria->publishedOnly === true) {
         $sql .= " AND rm_units.published='1'";
     }
     if (count($criteria->filters) > 0) {
         $filterConditions = array();
         foreach ($criteria->filters as $filter) {
             $filterConditions = array_merge($filterConditions, $this->_getConditions($filter));
         }
         $filterSQL = implode(" AND ", $filterConditions);
         $sql .= " AND " . $filterSQL;
     }
     if ($criteria->order !== null) {
         if ($criteria->order == 'random') {
             $sessionID = session_id();
             $random = hexdec($sessionID[0]);
             $sql .= " ORDER BY RAND(" . $random . ") ";
         } elseif ($criteria->order != 'price') {
             $sql .= " ORDER BY {$criteria->order} ";
         }
     }
     if ($criteria->count !== null) {
         $sql .= " LIMIT {$criteria->offset}, {$criteria->count} ";
     }
     return $this->_getBySQL($sql);
 }