Exemplo n.º 1
0
 /**
  * Returns all unit ids that are passed criteria option
  *
  * @param RM_Unit_Search_Criteria $criteria
  * @return array, false
  */
 function getAdvancedSearchUnitIDs(RM_Unit_Search_Criteria $criteria)
 {
     if (!$criteria->categories || count($criteria->categories) == 0) {
         return false;
     }
     $model = new RM_UnitCategories();
     $units = $model->getByCategories($criteria->categories);
     $unitIDs = array();
     foreach ($units as $row) {
         $unitIDs[] = $row->unit_id;
     }
     //we need to add code to support Group Module
     //we need to include every unit ID of a groups that main unit in group assigned to a category
     if (class_exists('RM_Groups')) {
         $groupUnitIDs = array();
         $groupsModel = new RM_Groups();
         $unitsModel = new RM_Units();
         foreach ($unitIDs as $unitID) {
             $unit = $unitsModel->get($unitID);
             if ($groupsModel->isMain($unit)) {
                 $units = $groupsModel->getGroupUnitsByMain($unit);
                 foreach ($units as $unit) {
                     $groupUnitIDs[] = $unit->getId();
                 }
             }
         }
         $unitIDs = array_merge($unitIDs, $groupUnitIDs);
         $unitIDs = array_unique($unitIDs);
     }
     return $unitIDs;
 }
Exemplo n.º 2
0
 public function formAction()
 {
     $reservationDetails = RM_Reservation_Manager::getInstance()->getAllDetails();
     $reservationsModel = new RM_Reservations();
     $unitModel = new RM_Units();
     $lang = RM_Environment::getInstance()->getLocale();
     //$chargetotal = 0;
     $bookingref = RM_Reservation_Manager::getInstance()->getReservationID();
     // create the description text
     $description = $bookingref . ": ";
     $count = 1;
     foreach ($reservationDetails as $details) {
         $unit = $details->getUnit();
         $period = $details->getPeriod();
         $unit_details = $unitModel->get($unit->getId(), $lang);
         $description .= $this->_translate->_('User.PayPal.Main', 'Selection') . " " . $count . "(" . $unit_details->name . " (" . $unit->getId() . ") " . $period->getStart() . " " . $this->_translate->_('User.PayPal.Main', 'To') . " " . $period->getEnd() . ")";
         $count += 1;
     }
     $plugin = new RM_Plugin_PayPal();
     $chargetotal = $plugin->getTotalPrice($reservationsModel->find($bookingref)->current());
     RM_Reservation_Manager::getInstance()->setPaymentTotal($chargetotal);
     $provider = new RM_Plugin_PayPal();
     $result = $provider->initialize($description, $bookingref, $chargetotal);
     $this->view->fields = $provider->getFields();
     $this->view->paypal_url = $provider->getPaypalURL();
     // return the json data so that the submit form can be rendered to pass this to paypal
 }
Exemplo n.º 3
0
 function editJsonAction()
 {
     $formID = $this->_getParam('formID');
     $formModel = new RM_Forms();
     $form = $formModel->find($formID)->current();
     // check if there are any units
     $unitDAO = new RM_Units();
     $unitTypeID = $this->_getParam('unitTypeID');
     if ($unitTypeID === null) {
         return array('data' => "{ 'error': true }", 'encoded' => true);
     }
     $unitTypeModel = new RM_UnitTypes();
     $unitType = $unitTypeModel->find($unitTypeID)->current();
     $total = $unitDAO->getAll(new RM_Unit_Search_Criteria(array('type' => $unitType)))->count();
     if ($unitTypeID == RM_UnitTypes::DEFAULT_TYPE && $total == 0) {
         $total = $unitDAO->getAll(new RM_Unit_Search_Criteria())->count();
     }
     if ($total == 0) {
         return array('data' => "{ 'error': true }", 'encoded' => true);
     }
     $panelModel = new RM_FormPanels();
     $panels = $panelModel->fetchByForm($formID);
     $jsonPanels = array();
     foreach ($panels as $panel) {
         $jsonPanels[] = '{id : "' . $panel->id . '", name : "' . $panel->name . '"}';
     }
     $unitTypeFormModel = new RM_UnitTypeForms();
     $unitTypeForm = $unitTypeFormModel->fetchBy($form, $unitType);
     $json = "{\n            formID: '" . $formID . "',\n            formName: '" . $form->name . "',\n            columns: " . $unitTypeForm->columns . ",\n            max_columns: " . $form->max_columns . ",\n            column1width: " . $unitTypeForm->column1width . ",\n            column2width: " . $unitTypeForm->column2width . ",\n            column3width: " . $unitTypeForm->column3width . ",\n            panels: [" . implode(',', $jsonPanels) . "],\n            formState: " . $unitTypeForm->state . ",\n            unitTypeID: {$unitTypeID},\n            unitTypeName: '" . $unitType->getName(RM_Environment::getInstance()->getLocale()) . "'\n        }";
     return array('data' => $json, 'encoded' => true);
 }
Exemplo n.º 4
0
 function datepickerAction()
 {
     ob_clean();
     $unitID = $this->_getParam('unit_id', null);
     $unitModel = new RM_Units();
     $unit = $unitModel->get($unitID);
     $reservationModel = new RM_Reservations();
     $reservations = $reservationModel->fetchAllForUnitCalendar($unit);
     $config = new RM_Config();
     $RMdate = new RM_Date();
     $jsonDisabledPeriods = new stdClass();
     $jsonDisabledPeriods->start = array();
     $jsonDisabledPeriods->end = array();
     foreach ($reservations as $period) {
         $jsonPeriod = new stdClass();
         $jsonPeriod->start = $config->convertDates($period->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
         $jsonPeriod->end = $config->convertDates($period->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT);
         // store the start date picker blocked periods
         $jsonDisabledPeriods->start[] = clone $jsonPeriod;
         $jsonPeriod->start = $RMdate->dateAdd($config->convertDates($period->start_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT), 1);
         $jsonPeriod->end = $RMdate->dateAdd($config->convertDates($period->end_datetime, RM_Config::JS_DATEFORMAT, RM_Config::PHP_DATEFORMAT), 1);
         $jsonDisabledPeriods->end[] = clone $jsonPeriod;
     }
     $json = Zend_Json::encode($jsonDisabledPeriods);
     $this->view->calendardata = $json;
     $this->view->unit_id = $unitID;
     echo $this->view->render('DailyPrices/datepicker.phtml');
     die;
 }
Exemplo n.º 5
0
 private function _getUnits()
 {
     $unitTypeDAO = new RM_UnitTypes();
     $unitsdao = new RM_Units();
     $units = $unitsdao->getAll(new RM_Unit_Search_Criteria());
     return $units;
 }
 public function updateunitJsonAction()
 {
     $unitID = $this->_getParam('unit_id');
     if ($unitID == null) {
         return array('data' => array('success' => false));
     }
     $typeID = $this->_getParam('rm_pages_module_unittype_selection_hidden');
     if ($typeID == null) {
         return array('data' => array('success' => false));
     }
     $unitModel = new RM_Units();
     $unit = $unitModel->find($unitID)->current();
     if ($unit == null) {
         return array('data' => array('success' => false));
     }
     $unit->type_id = (int) $typeID;
     $unitModel->update($unit->toArray(), "id=" . $unit->id);
     return array('data' => array('success' => true));
 }
Exemplo n.º 7
0
 public function allpanelsAction()
 {
     $unitModel = new RM_Units();
     $unitTypeID = $this->_getParam('unitTypeID');
     $unitTypeModel = new RM_UnitTypes();
     $unitType = $unitTypeModel->find($unitTypeID)->current();
     $unit = $unitModel->getAll(new RM_Unit_Search_Criteria(array('type' => $unitType, 'includeOptionUnits' => true, 'includeExcursionUnits' => true)))->current();
     if ($unitTypeID == RM_UnitTypes::DEFAULT_TYPE && $unit == null) {
         $unit = $unitModel->getAll(new RM_Unit_Search_Criteria())->current();
     }
     if ($unit == null) {
         $unit = $unitModel->createRow();
     }
     $this->view->unit = $unit;
     $this->view->admin = true;
     // this is required by captcha
     $panelModel = new RM_FormPanels();
     $panels = $panelModel->fetchAll();
     $this->view->panels = $panels;
 }
Exemplo n.º 8
0
 function getpriceJsonAction()
 {
     $unitIDs = $this->_getParam('ids');
     $start_datetime = $this->_getParam('start_datetime');
     $end_datetime = $this->_getParam('end_datetime');
     $adults = $this->_getParam("adults", 1);
     $children = $this->_getParam("children", 0);
     $infants = $this->_getParam("infants", 0);
     $persons = new RM_Reservation_Persons(array("adults" => $adults, "children" => $children, "infants" => $infants));
     $unitsDAO = new RM_Units();
     $stardateObj = new RM_Date(strtotime($start_datetime));
     $enddateObj = new RM_Date(strtotime($end_datetime));
     $periodObj = new RM_Reservation_Period($stardateObj, $enddateObj);
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     $units = explode(",", $unitIDs);
     $taxSystem = RM_Environment::getInstance()->getTaxSystem();
     $tax = 0;
     foreach ($units as $uid) {
         $unitObj = $unitsDAO->get($uid);
         $information = new RM_Prices_Information($unitObj, $periodObj, $persons);
         try {
             $subtotal = $subtotal + $priceSystem->getTotalUnitPrice($information);
         } catch (Exception $e) {
             // no return needed
         }
         $tax += $taxSystem->calculateTotalTax($unitObj, $subtotal);
     }
     // get currency symbol
     $config = new RM_Config();
     $currency_symbol = $config->get('rm_config_currency_symbol');
     // calculate the total
     $total = $subtotal + $tax;
     return array('data' => '{ data: [{
                             info: "Subtotal", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $subtotal . '"
                     },{
                             info: "Tax", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $tax . '"
                     },{
                             info: "Total", value: "' . $currency_symbol['rm_config_currency_symbol'] . ' ' . $total . '"
                     }]
                 }', 'encoded' => true);
 }
Exemplo n.º 9
0
 /**
  * Validate information from reservation manager object, 'cause we are on the final step
  * before payment process.
  *
  * @param Zend_Request_Interface $request
  * @return bool
  */
 function validate($request)
 {
     $this->_request = $request;
     $valid = true;
     $state = $this->_form->getState();
     foreach ($state as $column) {
         foreach ($column as $panel) {
             if (in_array($panel->id, $this->_neeedToBeValidatedPanelsIDs)) {
                 $methodName = '_' . $panel->id . '_validate';
                 $valid &= $this->{$methodName}();
             }
         }
     }
     $manager = RM_Reservation_Manager::getInstance();
     $savedDetails = $manager->getAllDetails();
     $unitModel = new RM_Units();
     foreach ($savedDetails as $details) {
         $valid &= $unitModel->isAvailableUnitbyDate($details->getUnit(), $details->getPeriod());
     }
     return $valid;
 }
Exemplo n.º 10
0
 public function advancedvalidateJsonAction()
 {
     $this->_withoutView();
     $formModel = new RM_Forms();
     $form = $formModel->find('advancedsearch')->current();
     $formvalid = $form->validate($this->getRequest());
     $data = $this->_getParam('search', array());
     // count records to be returned
     $criteria = new RM_Unit_Search_Criteria($data);
     $criteria->publishedOnly = true;
     $unitModel = new RM_Units();
     $totalUnits = $unitModel->getAll($criteria)->count();
     // count records end
     if ($formvalid == false) {
         $errors = $form->getErrors();
         $returnData = array('data' => array('success' => false, 'errors' => $errors, 'count' => $totalUnits));
     } else {
         $errors = $form->getErrors();
         $returnData = array('data' => array('success' => true, 'errors' => null, 'count' => $totalUnits));
     }
     return $returnData;
 }
Exemplo n.º 11
0
 /**
  * Returns the list configuration for the unit assignment.
  *
  * This creates a JS variable containing the list configuration/setup for
  * the reservation list. This is implicated in list.js
  *
  * @param  	request id  the reservation id.
  * @param  	request type    if this is a new or existing reservation.
  * @param  	request start_datetime  the selected start date.
  * @param  	request end_datetime  the selected end date.
  * @return   json    information required to configure unit selection grid.
  */
 public function unitgridJsonAction()
 {
     $fieldsDAO = new RM_ReservationConfig();
     $configFields = $fieldsDAO->getAdminEdit()->toArray();
     foreach ($configFields as $key => $configField) {
         $metainfo[] = $configField['admin_edit_preferences'];
     }
     $fieldsDAO = new RM_UnitConfig();
     $configFields = $fieldsDAO->getAllReservationFields()->toArray();
     foreach ($configFields as $key => $configField) {
         //We need to check reservations and
         //TODO: this is some kind of hardcode we need to remove this later and create some other GOOD code :)
         if ($configField['column_name'] == 'id') {
             $id = $this->_getParam('id');
             //reservation ID
             $type = $this->_getParam('type');
             //indicates if this is a new reservation.
             $reservationModel = new RM_Reservations();
             // if the type = new there will not be any reservation information for this
             // so we need to construct some information so that we can return the available units.
             if ($type == 'new') {
                 $reservation->id = $id;
                 $reservation->start_datetime = $this->_getParam('start_datetime');
                 $reservation->end_datetime = $this->_getParam('end_datetime');
             } else {
                 // if this is not new then load the reservation info...
                 $reservation = $reservationModel->find($id)->current();
             }
             $unitModel = new RM_Units();
             $availableUnits = $unitModel->getAllAvailableForReservation($reservation, $reservationModel);
             foreach ($availableUnits as $unit) {
                 $editorStore[] = "['{$unit->id}', '{$unit->id}']";
             }
             $editorStore = "[" . implode(',', $editorStore) . "]";
             if ($type == 'new') {
                 $metainfo[] = str_replace("'---store---'", $editorStore, $configField['admin_new_reservation_preferences']);
             } else {
                 $metainfo[] = str_replace("'---store---'", $editorStore, $configField['admin_edit_reservation_preferences']);
             }
         } else {
             if ($type == 'new') {
                 $metainfo[] = $configField['admin_new_reservation_preferences'];
             } else {
                 $metainfo[] = $configField['admin_edit_reservation_preferences'];
             }
         }
     }
     return array('data' => "{fields:[" . implode(',', $metainfo) . "]}", 'encoded' => true);
 }
Exemplo n.º 12
0
 public function getdefaulttimesJsonAction()
 {
     $unitID = $this->_getParam('uid');
     $unitModel = new RM_Units();
     $unit = $unitModel->find($unitID)->current();
     // price system
     $priceSystem = RM_Environment::getInstance()->getPriceSystem()->getRealPriceSystem($unit);
     $configClassName = "RM_Unit" . $priceSystem->name . "Config";
     $priceConfigObject = new $configClassName();
     $defaultStartTime = $priceConfigObject->fetchValueByUnit($unit->id, 'default_start_time');
     $defaultEndTime = $priceConfigObject->fetchValueByUnit($unit->id, 'default_end_time');
     return array('data' => array("defaultstarttime" => $defaultStartTime, "defaultendtime" => $defaultEndTime));
 }
Exemplo n.º 13
0
 /**
  * this creates the JSON for the unit selection on the coupons grid
  * @return array used to construct the json result
  */
 public function unitlistJsonAction()
 {
     $dao = new RM_Units();
     $units = $dao->getAll(new RM_Unit_Search_Criteria())->toArray();
     // add *all units* selection to the start of the list
     $units[] = array('id' => '0', 'name' => RM_Environment::getInstance()->getTranslation()->_('Admin.Taxes.Edit', 'AllUnits'));
     return array('data' => $units);
 }
Exemplo n.º 14
0
 public function insertNewReservation($user, $unitDetails, $inprogres = 0, $confirmed = 1, $bookingRef = null)
 {
     //1. add information into rm_reservation
     if ($user->id) {
         $userID = $user->id;
     } else {
         // at this point the user does not exist in ResMania let's add it...
         $userData = array();
         foreach ($user as $key => $value) {
             if ($key == 'name') {
                 $nameArray = explode(" ", $value);
                 $userData['first_name'] = $nameArray[0];
                 $userData['last_name'] = $nameArray[1] . " " . $nameArray[2];
             }
             $userData[$key] = $value;
         }
         $userData['group_id'] = 0;
         unset($userData['id']);
         $rmUsers = new RM_Users();
         $userID = $rmUsers->insert($userData);
     }
     $reservation = $this->createRow();
     $reservation->user_id = $userID;
     $reservation->confirmed = $confirmed;
     $reservation->in_progress = $inprogres;
     // this will hide the reservation until we have completed the process
     if ($bookingRef !== null) {
         $reservation->id = $bookingRef;
     }
     $reservation->creation_datetime = date(RM_Config::MYSQL_DATEFORMAT);
     //current server datetime
     $reservationID = $reservation->save();
     //2. add information into rm_reservation_details
     $detailsModel = new RM_ReservationDetails();
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     foreach ($unitDetails as $unitDetail) {
         $detail = $detailsModel->createRow();
         $selectedUnit = $unitDetail->getUnit();
         // get the master unit
         if (class_exists("RM_Groups")) {
             $groupsObject = new RM_Groups();
             $isMaster = $groupsObject->isMain($selectedUnit);
             if (!$isMaster) {
                 $unitModel = new RM_Units();
                 $group = $groupsObject->getByUnit($selectedUnit);
                 if ($group != null) {
                     try {
                         $groupID = $group->main_unit_id;
                         $selectedUnit = $unitModel->get($groupID, RM_Environment::getInstance()->getLocale());
                     } catch (Exception $e) {
                     }
                 }
             }
         }
         $information = new RM_Prices_Information($selectedUnit, $unitDetail->getPeriod(), $unitDetail->getPersons(), $unitDetail->getOtherInfo());
         try {
             $detail->total_price = $priceSystem->getTotalUnitPrice($information);
         } catch (Exception $e) {
             $detail->total_price = 0;
         }
         $detail->reservation_id = $reservationID;
         $detail->unit_id = $unitDetail->getUnit()->getId();
         $detail->start_datetime = $unitDetail->getPeriod()->getStart()->toMySQL();
         $detail->end_datetime = $unitDetail->getPeriod()->getEnd()->toMySQL();
         $detail->adults = $unitDetail->getPersons()->getAdults() == 0 ? 1 : $unitDetail->getPersons()->getAdults();
         $detail->children = $unitDetail->getPersons()->getChildren();
         $detail->infants = $unitDetail->getPersons()->getInfants();
         // process other information (this allows the price system to manage
         // other data i.e: board_types for the hospitality price module
         $otherInfo = $unitDetail->getOtherInfo();
         if ($otherInfo) {
             foreach ($otherInfo as $key => $value) {
                 $detail->{$key} = $value;
             }
         }
         $detail->save();
         $this->_insertDetailExtraData($unitDetail, $detail);
     }
     return $reservationID;
 }
Exemplo n.º 15
0
 public function reservationsJsonAction()
 {
     $unitID = $this->_getParam('unit_id', null);
     $startdate = $this->_getParam('startdate', null);
     $enddate = $this->_getParam('enddate', null);
     // unit dao
     $unitsDAO = new RM_Units();
     $unitObject = $unitsDAO->find($unitID)->current();
     $filter[] = array('field' => 'start_datetime', 'data' => array('type' => 'date', 'value' => $startdate, 'comparison' => 'gt'));
     $filter[] = array('field' => 'end_datetime', 'data' => array('type' => 'date', 'value' => $enddate, 'comparison' => 'lt'));
     $filters[] = array('field' => 'confirmed', 'data' => array('type' => 'numeric', 'value' => 1, 'comparison' => 'eq'));
     // reservation data
     $reservationsDAO = new RM_Reservations();
     $reservations = $reservationsDAO->fetchAllByUnit($unitObject, $filter);
     foreach ($reservations as $reservation) {
         $detailJson = new stdClass();
         $detailJson->Id = $reservation->id;
         $detailJson->ResourceId = $unitID;
         $detailJson->StartDate = $reservation->start_datetime;
         $detailJson->Color = 'red';
         $detailJson->EndDate = $reservation->end_datetime;
         $detailsJson[] = $detailJson;
     }
     return array('data' => $detailsJson);
 }
Exemplo n.º 16
0
 private function _getUnits()
 {
     $dao = new RM_Units();
     $criteria = new RM_Unit_Search_Criteria(array('language' => RM_Environment::getInstance()->getLocale()), true);
     $units = $dao->getAll($criteria);
     $result = array();
     if (count($units->toArray()) === 0) {
         return null;
     }
     // get all the master group units
     $count = 1;
     // the menu id
     $groupTracker = array();
     foreach ($units as $unitRow) {
         $unit = $unitRow->toArray();
         if (isset($unit['group_id'])) {
             if ($unitRow->isTemplateUnit() === (int) $unit['unit_id']) {
                 // template units (root units)
                 $std = new stdClass();
                 $std->id = 'Units_EditJson_' . $unit['id'];
                 $std->text = $unit['name'];
                 $std->expanded = 'true';
                 $std->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon';
                 $std->children = array();
                 $result[$count] = $std;
                 $groupTracker[$count] = $unit['group_id'];
                 $count += 1;
             }
         } else {
             // this is not a grouped unit - this is the standard unit (not grouped)
             $std = new stdClass();
             $std->id = 'Units_EditJson_' . $unit['id'];
             $std->text = $unit['name'];
             $std->leaf = 'true';
             $std->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon';
             $result[$count] = $std;
             $groupTracker[$count] = 0;
             $count += 1;
         }
     }
     // now loop through all units and assign sub units to the template units
     // but only if they are a sub unit.
     foreach ($units as $unitRow) {
         $unit = $unitRow->toArray();
         // handle groups
         if (isset($unit['group_id'])) {
             if ($unitRow->isTemplateUnit() !== (int) $unit['unit_id']) {
                 // sub unit
                 $childUnit = new stdClass();
                 $childUnit->id = 'Units_EditJson_' . $unit['id'];
                 $childUnit->text = $unit['name'];
                 $childUnit->leaf = 'true';
                 $childUnit->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon';
                 // add it to the parent leaf
                 foreach ($groupTracker as $key => $value) {
                     if ($unit['group_id'] == $value) {
                         $result[$key]->children[] = $childUnit;
                     }
                 }
             }
         }
     }
     // we have to resort here as the menu needs consecutive numbering
     foreach ($result as $value) {
         $final[] = $value;
     }
     return $final;
 }
Exemplo n.º 17
0
 /**
  * Updates configuration.
  *
  * @param  	request all values this values for the config update
  * @return 	json    boolean response of true or false in json format (true is success)
  */
 function updateJsonAction()
 {
     $model = new RM_Config();
     $fields = $model->fetchAll();
     foreach ($fields as $field) {
         switch ($field->xtype) {
             case "checkbox":
                 $value = $this->_getParam($field->id);
                 break;
             default:
                 $value = $this->_getParam($field->id, $this->_getParam($field->id . "_hidden"));
         }
         if ($value !== null) {
             $field->value = $value;
             $field->save();
         }
     }
     // process image resizing
     if ($this->_getParam('image_resize', 0) == 1) {
         //1. resize images for media, if we will later add extra options for admin thumnails
         //$mediaManager = new RM_Media_Manager();
         //$mediaManager->resize();
         //2. resize images for units
         $unitModel = new RM_Units();
         $units = $unitModel->fetchAll();
         foreach ($units as $unit) {
             $unitMediaManager = new RM_Media_Unit_Manager($unit);
             $unitMediaManager->resize();
         }
     }
     return array('data' => array('success' => true));
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
 /**
  * @param array $row
  * @return floar
  */
 private function _calculatePrice($row)
 {
     $model = new RM_Units();
     $unit = $model->find($row['id'])->current();
     $information = new RM_Prices_Information($unit, $this->_period, $this->_persons);
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     $price = $priceSystem->getLowestUnitPrice($information);
     if ($this->_isDefaultPeriod == false) {
         try {
             $price = $priceSystem->getTotalUnitPrice($information);
         } catch (Exception $e) {
             $price = 0;
         }
     }
     if ($price != 0 && $this->_showPriceWithTax) {
         $price += $this->_taxSystem->calculateTotalTax($unit, $price);
     }
     return $price;
 }
Exemplo n.º 20
0
 /**
  * Insert a unit by its primary key
  *
  * @param array $unit Array with all unit information
  * @param string $iso ISO language code ('cause we got all unit info with language dependent fields)
  * @param boolean $fromGUI This parameter told us was that data from GUI or it's internal usage.
  * @return mixed The primary key of the row inserted.
  */
 public function insert($unit, $iso, $fromGUI = false)
 {
     $unitTypeDAO = new RM_UnitTypes();
     $type = $unitTypeDAO->find($unit['type_id'])->current();
     list($fields, $languageFields) = $this->_getFieldsByType($type);
     $unitArray = array();
     $languageArray = array();
     foreach ($fields as $field) {
         $unitArray[$field->column_name] = $unit[$field->column_name];
     }
     foreach ($languageFields as $field) {
         $languageArray[$field->column_name] = $unit[$field->column_name];
     }
     //TODO: this code need to be more flexible to do not use UnitTypeManager module
     $manager = new RM_Module_UnitTypeManager();
     $unitArray['type_id'] = $manager->getDefaultUnitType()->id;
     if ($fromGUI) {
         $languageArray['unit_id'] = $this->insertFromGUI($unitArray);
     } else {
         $languageArray['unit_id'] = parent::insert($unitArray);
     }
     $unitModel = new RM_Units();
     $newUnit = $unitModel->createRow(array('id' => $languageArray['unit_id']));
     $mediaManager = new RM_Media_Unit_Manager($newUnit);
     $mediaManager->createFolder();
     //we need to create a unit detail row for every language installed in the system
     $languageModel = new RM_Languages();
     $languages = $languageModel->fetchAll();
     $unitLanguageModel = new RM_UnitLanguageDetails();
     foreach ($languages as $language) {
         $languageArray['iso'] = $language->iso;
         $unitLanguageModel->insert($languageArray);
     }
     return $languageArray['unit_id'];
 }
Exemplo n.º 21
0
 function _validateUnit()
 {
     $unitModel = new RM_Units();
     $unit = $unitModel->find($this->_request->getParam('unit_id', null))->current();
     if ($unit == null) {
         $this->_errors[] = 'SelectedUnitDoesNotExists';
         return false;
     }
     return true;
 }
Exemplo n.º 22
0
 /**
  * This method is for classification media file
  */
 function classificationmediaJsonAction()
 {
     $unitID = $this->_getParam('unit_id', null);
     if ($unitID == null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'UnitIDNotSpecified')));
     }
     $unitModel = new RM_Units();
     $unit = $unitModel->find($unitID)->current();
     if ($unit == null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'WrongUnitID')));
     }
     $info = $this->_getParam('info', null);
     if ($info == null) {
         return array('data' => array('success' => false, 'error' => $this->_translate->_('Admin.Unit.Media', 'TypeInformationNotSpecified')));
     }
     $fileTypeModel = new RM_UnitMediaFileTypes();
     $infoObject = Zend_Json::decode($info);
     $result = $fileTypeModel->changeOrder($unit, $infoObject);
     if ($result) {
         return array('data' => array('success' => true));
     } else {
         return array('data' => array('success' => false));
     }
 }
Exemplo n.º 23
0
 public function updateJsonAction()
 {
     $unit = $this->_getParam('edit_unit');
     $unit['color'] = ltrim($this->_getParam('color'), "#");
     $dao = new RM_Units();
     // update the unit record
     $dao->updateUnit($unit);
     if (isset($unit['group_id'])) {
         // make sure that sub units are converted to the same unit type
         if (class_exists(RM_Groups)) {
             $groups = new RM_Groups();
             // get the unit object
             $unitObject = $dao->get($unit['id'], null, array('description', 'summary'));
             if (!$groups->isMain($unitObject)) {
                 // if it's not a main unit, then update the unit to the same unit type as the main unit
                 $allGroupedUnits = $groups->getGroupUnitsByMain($unitObject);
                 // find the main unit id...
                 foreach ($allGroupedUnits as $groupUnit) {
                     if ($groups->isMain($groupUnit)) {
                         $mainUnitID = $groupUnit->id;
                     }
                 }
                 // get the main unit object
                 $mainUnitObject = $dao->get($mainUnitID, null, array('description', 'summary'));
                 // get the type for the main unit
                 $rmUnitTypes = new RM_UnitTypes();
                 $typeInfo = $rmUnitTypes->getByUnit($mainUnitObject)->toArray();
                 // update the subunit to the same type
                 $unit['type_id'] = (int) $typeInfo['id'];
                 $dao->updateUnit($unit);
             }
         }
     }
     return array('data' => array('success' => true, 'msg' => ''));
 }
Exemplo n.º 24
0
 public function uninstall()
 {
     parent::uninstall();
     $unitModel = new RM_Units();
     $unitModel->update(array('type_id' => RM_UnitTypes::DEFAULT_TYPE, 'published' => 0), 'type_id=2');
 }
Exemplo n.º 25
0
 public function findUnit($locale = null)
 {
     if ($locale == null) {
         $locale = RM_Environment::getInstance()->getLocale();
     }
     $model = new RM_Units();
     return $model->get($this->unit_id, $locale);
 }
Exemplo n.º 26
0
 /**
  * Creates the unit CSS for the calendar rendering
  * This is just generated at boot
  */
 public static function createUnitColorCSS()
 {
     $unitModel = new RM_Units();
     $units = $unitModel->getAll(new RM_Unit_Search_Criteria());
     $html = "";
     foreach ($units as $unit) {
         if (isset($unit->color) && $unit->color !== "") {
             $color = $unit->color;
         } else {
             $color = '0033FF';
         }
         $html .= "\n                .x-cal-{$unit->id},\n                .x-cal-{$unit->id}-x .ext-cal-evb,\n                .ext-ie .x-cal-{$unit->id}-ad,\n                .ext-opera .x-cal-{$unit->id}-ad {\n                    color: #{$color};\n                }\n                .ext-cal-day-col .x-cal-{$unit->id},\n                .ext-dd-drag-proxy .x-cal-{$unit->id},\n                .x-cal-{$unit->id}-ad,\n                .x-cal-{$unit->id}-ad .ext-cal-evm,\n                .x-cal-{$unit->id} .ext-cal-picker-icon,\n                .x-cal-{$unit->id}-x dl,\n                .x-calendar-list-menu li em .x-cal-{$unit->id} {\n                    background: #{$color};\n                }\n            ";
     }
     return $html;
 }
Exemplo n.º 27
0
 /**
  * Action for validating unit details form parameters.
  * If some of the parameters are invalid this method will redirect user to previous page with error
  * text messages about every wrong parameter.
  * If all unit detail information is valid this method will save unit information into global
  * reservation manager object and will redirect user to the next step of the reservation process.
  */
 function detailsvalidateAction()
 {
     $this->_withoutView();
     $unitID = $this->_getParam('unit_id', null);
     if ($unitID == null) {
         $this->_redirect('Unit', 'list');
         return;
     }
     // this is the subunits if groups is being implemented
     $selectedUnitIds = json_decode($this->_getParam('selected_unit_ids', "[]"));
     $quantity = $this->_getParam('quantity', 1);
     $formModel = new RM_Forms();
     $form = $formModel->find('unitdetails')->current();
     $valid = $form->validate($this->getRequest());
     if ($valid == false) {
         RM_Reservation_Manager::getInstance()->setFormErrors('unitdetails', $form->getErrors())->save();
         $this->_redirect('Unit', 'details', array('unit_id' => $unitID));
     }
     //We have a priority to use a user selected dates on the page, not from criteria
     if ($this->_request->getParam('rm_calendar_dates', null) != null) {
         // get the dates from the calendar selection
         $datesString = $this->_request->getParam('rm_calendar_dates');
         $dates = explode(',', $datesString);
         $startDateMySQL = $dates[0];
         $endDateMySQL = $dates[count($dates) - 1];
         $adults = $this->_getParam("adults", 1);
         $children = $this->_getParam("children", 0);
         $infants = $this->_getParam("infants", 0);
         $persons = new RM_Reservation_Persons(array("adults" => $adults, "children" => $children, "infants" => $infants));
     } else {
         $criteria = RM_Reservation_Manager::getInstance()->getCriteria();
         $startDateMySQL = $criteria->start_datetime;
         $endDateMySQL = $criteria->end_datetime;
         $persons = new RM_Reservation_Persons(array("adults" => $criteria->adults, "children" => $criteria->children, "infants" => $criteria->infants));
     }
     $period = new RM_Reservation_Period(new RM_Date(strtotime($startDateMySQL)), new RM_Date(strtotime($endDateMySQL)));
     $unitModel = new RM_Units();
     $otherinfo = $this->_getParam("otherInfo", array());
     $manager = RM_Reservation_Manager::getInstance();
     // use a temporary session to pass a value to the groups module init
     $_SESSION["returnAllUnits"] = true;
     // get price...
     $unit = $unitModel->get($unitID, RM_Environment::getInstance()->getLocale(), array("summary", "description"));
     $information = new RM_Prices_Information($unit, $period, $persons, $otherinfo);
     $priceSystem = RM_Environment::getInstance()->getPriceSystem();
     try {
         $calculatedTotalPrice = $priceSystem->getTotalUnitPrice($information);
     } catch (RM_Exception $e) {
         RM_Reservation_Manager::getInstance()->setFormErrors('unitdetails', array($e->getMessage()))->save();
         $this->_redirect('Unit', 'details', array('unit_id' => $selectedUnitId));
     }
     $selectedCount = 1;
     // loop through the selected units and save these
     foreach ($selectedUnitIds as $selectedUnitId) {
         if ($selectedCount >= $quantity) {
             break;
         }
         $selectedUnit = $unitModel->get($selectedUnitId, RM_Environment::getInstance()->getLocale());
         $details = new RM_Reservation_Details($selectedUnit, $period, $persons, $otherinfo, $calculatedTotalPrice);
         $manager->addDetails($details);
         $selectedCount += 1;
     }
     $manager->resetFormErrors('unitdetails')->save();
     $details = $manager->getAllDetails();
     // reset the returnAllUnits if it's set
     unset($_SESSION["returnAllUnits"]);
     $cmsUser = RM_Environment::getConnector()->getUser();
     if ($cmsUser->isGuest() == false) {
         $user = $cmsUser->findResmaniaUser();
         if ($user !== null) {
             RM_Reservation_Manager::getInstance()->setUser($user);
             $this->_redirect('Reservations', 'summary');
         }
     } elseif (RM_Reservation_Manager::getInstance()->getUser() !== null) {
         $this->_redirect('Reservations', 'summary');
     }
     $this->_redirect('User', 'userdetails');
 }