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 }
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; }
/** * 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; }
public function loadeditJsonAction() { $unit_id = $this->_getParam('id'); $unitDAO = new RM_Units(); $unit = $unitDAO->get($unit_id); $rmUnitTypes = new RM_UnitTypes(); $typeInfo = $rmUnitTypes->getByUnit($unit)->toArray(); $unittypes = $rmUnitTypes->getAll()->toArray(); $json = new stdClass(); $json->currentUnitType = $typeInfo; $json->allUnitTypes = $unittypes; return array('data' => $json, 'encoded' => false); }
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); }
/** * Gets the calendar Data * * @return JSON */ private function _getdata($startRange = false, $endRange = false) { if (!$startRange || !$endRange) { $startRange = date("Y-m-d"); $endRange = date("Y-m-d"); } $unitModel = new RM_Units(); $units = $unitModel->getAll(new RM_Unit_Search_Criteria()); $unitModel = new RM_Units(); $reservationModel = new RM_Reservations(); $config = new RM_Config(); $evtsArray = array(); // add 6 months to either side of the reservation $RMDate = new RM_Date(); $start = $RMDate->dateSub($startRange, 180); $end = $RMDate->dateAdd($endRange, 180); $filter = array(); $filter['data']['type'] = 'date'; $filter['field'] = 'start_datetime'; $filter['data']['comparison'] = 'gt'; $filter['data']['value'] = $start; $filterArray[] = $filter; $filter = array(); $filter['data']['type'] = 'date'; $filter['field'] = 'end_datetime'; $filter['data']['comparison'] = 'lt'; $filter['data']['value'] = $end; $filterArray[] = $filter; $filter = array(); $filter['data']['type'] = 'numeric'; $filter['field'] = 'in_progress'; $filter['data']['comparison'] = 'eq'; $filter['data']['value'] = 0; $filterArray[] = $filter; foreach ($units as $unit) { $unit = $unitModel->get($unit->id); $reservations = $reservationModel->fetchAllByUnit($unit, $filterArray); foreach ($reservations as $period) { $idArray = explode("-", $period->id); $id = (int) $idArray[1]; // check time $ad = true; // all day $starttime = explode(" ", $period->start_datetime); if ($starttime[1] !== "00:00:00") { $ad = false; } $endtime = explode(" ", $period->end_datetime); if ($endtime[1] !== "23:30:00") { $ad = false; } $evtsArray[] = array("id" => $id, "cid" => $unit->id, "uid" => (int) $period->user_id, "title" => "<span style='text-align:center;width:70%;'>" . $period->id . " " . $unit->name . "(" . $unit->id . ")</span>", "start" => $period->start_datetime, "end" => $period->end_datetime, "ad" => $ad); } } return array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => $evtsArray); }
function setdatecriteriaJsonAction() { $this->_withoutView(); $unitID = $this->_getParam('unit_id', null); $unitModel = new RM_Units(); $unit = $unitModel->get($unitID, RM_Environment::getInstance()->getLocale(), array("summary", "description")); if ($unit == null) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'SelectedUnitDoesNotExists'))); } //TODO: we need to check dates for null $startdate = $this->_getParam('startdate', null); $enddate = $this->_getParam('enddate', null); $quantity = (int) $this->_getParam('qty', 1); //TODO: we need to check dates for rigth format to parse them into objects //check if start date is after end date $startDateObject = new RM_Date(strtotime($startdate)); $endDateObject = new RM_Date(strtotime($enddate)); if ($endDateObject->isEarlier($startDateObject)) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'StartAfterEnd'))); } // check if the dates are available... $period = new RM_Reservation_Period($startDateObject, $endDateObject); $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)); // get otherinfo - this is non-standard price system information. $otherinfo = Zend_Json::decode($this->_getParam("otherinfo", "{}")); // while we don't need the price here, getTotalUnitPrice will also check the // period selected is valid. $information = new RM_Prices_Information($unit, $period, $persons, $otherinfo); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); try { $calculatedTotalPrice = $priceSystem->getTotalUnitPrice($information); } catch (RM_Exception $e) { return array('data' => array('success' => false, 'error' => $e->getMessage())); } // get the default start/end times... $startArray = explode(" ", $startdate); $endArray = explode(" ", $enddate); $realPriceSystem = $priceSystem->getRealPriceSystem($unit); $configObjectName = "RM_Unit" . $realPriceSystem->name . "Config"; // ie: RM_UnitDailyPricesConfig $priceConfigObject = new $configObjectName(); $recreatePeriod = false; // if the start time is null or 00:00:00 load the default price system times if (!isset($startArray[1]) || $startArray[1] === "" || $startArray[1] === "00:00:00") { try { // placed in a try so that if the price module returns an exception for default_end_time it does not crash this $defaultStartTime = $priceConfigObject->fetchValueByUnit($unitID, 'default_start_time'); $startdate = $startArray[0] . " " . $defaultStartTime; $startDateObject = new RM_Date(strtotime($startdate)); $recreatePeriod = true; } catch (Exception $e) { } } // if the end time is null or 00:00:00 load the default price system times if (!isset($endArray[1]) || $endArray[1] === "" || $endArray[1] === "23:30:00") { try { // placed in a try so that if the price module returns an exception for default_end_time it does not crash this $defaultEndTime = $priceConfigObject->fetchValueByUnit($unitID, 'default_end_time'); $enddate = $endArray[0] . " " . $defaultEndTime; $endDateObject = new RM_Date(strtotime($enddate)); $recreatePeriod = true; } catch (Exception $e) { } } // if the times have been added re-create the period object with the times... if ($recreatePeriod) { $period = new RM_Reservation_Period($startDateObject, $endDateObject); } // get the unit setting for the setting availablity_check // this could fail if the price system doesn't have this setting so it is wrapped in a try try { $availabilityCheck = $priceConfigObject->fetchValueByUnit($unitID, 'availablity_check'); } catch (Exception $e) { $availabilityCheck = "1"; } // check availability if ($availabilityCheck == "1") { $isAvailable = $unitModel->isAvailableUnitbyDate($unit, $period); if (!$isAvailable) { return array('data' => array('success' => false, 'error' => $this->_translate->_('User.DatePicker', 'ReselectDates'))); } } $data = array(); $data['start_datetime'] = $startdate; $data['end_datetime'] = $enddate; $data['adults'] = $adults; $data['children'] = $children; $data['infants'] = $infants; $data['otherinfo'] = $otherinfo; $data['quantity'] = $quantity; $criteria = new RM_Unit_Search_Criteria($data); $criteria->publishedOnly = true; RM_Reservation_Manager::getInstance()->resetCriteria()->setCriteria($criteria); // handle groups $isGroup = $unit->isGroup(); $groupID = $unit->getGroupId(); // if this is a group we need to get an available unit from the 'pool' if ($isGroup) { // get available sub units $AllavailableSubUnits = $unit->getAllSubUnits($criteria, $unit); foreach ($AllavailableSubUnits as $subunit) { if ($subunit->getGroupId() === $unit->getGroupId()) { $availableSubUnits[] = $subunit; } } // set a temporary session variable this is used in the groups row class $_SESSION["returnAllUnits"] = true; $units = array(); $subunits = array(); $selectedCount = 0; // if there is a unit available take the first one from the returned units... foreach ($availableSubUnits as $potentialUnit) { if ($selectedCount >= $quantity) { break; } $details = new RM_Reservation_Details($potentialUnit, $period, $persons, $otherinfo); RM_Reservation_Manager::getInstance()->addDetails($details); $selectedCount += 1; } // if the number of units saved to the reservation are not equal to the quantity also add the master unit if ($selectedCount < $quantity) { // add the master unit also $details = new RM_Reservation_Details($unit, $period, $persons, $otherinfo); RM_Reservation_Manager::getInstance()->addDetails($details); } } else { $details = new RM_Reservation_Details($unit, $period, $persons); RM_Reservation_Manager::getInstance()->addDetails($details); } // remove the temporary session variable unset($_SESSION["returnAllUnits"]); return array('data' => array('success' => true)); }
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); }
/** * 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'); }
/** * Method for price calculation for the reservation edit page */ public function getpriceJsonAction() { $unit_id = $this->_getParam('unit_id'); $periods = $this->_getParam('periods'); $persons = $this->_getParam('persons'); $otherinfo = $this->_getParam('otherinfo', array()); // format the other info data $otherinfoArray = Zend_Json::decode($otherinfo); $unitModel = new RM_Units(); $priceSystem = RM_Environment::getInstance()->getPriceSystem(); $jsonDetails = array(); $unit = $unitModel->get($unit_id); $currentUnit = $unit; // save this information for later // group handling (only used when the groups is enabled) $templateUnitID = $unit->isTemplateUnit(); if ($templateUnitID !== null) { if ($templateUnitID !== (int) $unit_id) { // if it's not the main template unit then switch to the main template // unit to get the price information $unit = $unitModel->get($templateUnitID); } } $jsonUnit = new stdclass(); $jsonUnit->name = $currentUnit->name; $jsonUnit->id = $currentUnit->id; $periodArray = Zend_Json::decode($periods); $personArray = Zend_Json::decode($persons); $jsonPeriod = new stdclass(); $config = new RM_Config(); $jsonPeriod->start = $config->convertDates($periodArray['start'], RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT); $jsonPeriod->end = $config->convertDates($periodArray['end'], RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT); $json = new stdclass(); $json->unit = $jsonUnit; $json->period = $jsonPeriod; $json->otherinfo = $otherinfoArray[0]; $persons = new RM_Reservation_Persons($personArray); $information = new RM_Prices_Information($unit, new RM_Reservation_Period(new RM_Date(strtotime($periodArray['start'])), new RM_Date(strtotime($periodArray['end']))), $persons, $otherinfoArray[0]); $jsonResponce = new stdClass(); try { $totalPrice = $priceSystem->getTotalUnitPrice($information); $jsonResponce->success = true; } catch (RM_Exception $e) { $totalPrice = 0; $jsonResponce->error = $e->getMessage(); $jsonResponce->success = false; } $config = new RM_Config(); $currencySymbol = $config->getValue('rm_config_currency_symbol'); $json->price = $currencySymbol . $totalPrice; $jsonDetails[] = $json; $jsonResponce->details = $jsonDetails; return array('data' => $jsonResponce); }
public function findUnit($locale = null) { if ($locale == null) { $locale = RM_Environment::getInstance()->getLocale(); } $model = new RM_Units(); return $model->get($this->unit_id, $locale); }
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' => '')); }
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; }