public function listJsonAction() { $criteria = new RM_Unit_Search_Criteria(array(), true); $dao = new RM_Units(); $filters = $this->_getParam('filter', array()); $isSelector = $this->_getParam('selector', false); $showOnlyAvailable = $this->_getParam('showOnlyAvailable', false); if ($showOnlyAvailable) { $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($this->_getParam('start_datetime'))), new RM_Date(strtotime($this->_getParam('end_datetime')))); $unitsReserved = $dao->getReservedUnits($reservationPeriod); $unitArray = array(); foreach ($unitsReserved as $unit) { $unitArray[] = $unit->getId(); } if (count($unitArray) > 0) { $filters[] = array('field' => "id", 'data' => array('type' => "listin", 'value' => implode(",", $unitArray), 'comparison' => 'notin')); } } if ($this->_getParam('reservationID') !== null) { $reservationID = $this->_getParam('reservationID'); $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); if ($reservation !== null) { $detailsModel = new RM_ReservationDetails(); $details = $detailsModel->getAllByReservation($reservation); $reservedUnitIDs = array(); foreach ($details as $detail) { $reservedUnitIDs[] = $detail->unit_id; } if (count($reservedUnitIDs) > 0) { $filters[] = array('field' => "id", 'data' => array('type' => "listin", 'value' => implode(",", $reservedUnitIDs), 'comparison' => 'notin')); } } } $criteria->filters = $filters; $units = $dao->getAll($criteria)->toArray(); $criteria->offset = $this->_getParam('start'); $criteria->order = $this->_getParam('sort', 'id') . ' ' . $this->_getParam('dir', 'DESC'); $criteria->count = $this->_getParam('limit'); $total = $dao->getAll($criteria)->count(); $json = new stdClass(); $json->total = $total; $json->data = $units; return array('data' => $json); }
/** * saves the new reservation selection * * @return JSON */ public function insertJsonAction() { // get the data $data = Zend_Json::decode($this->_getParam('data')); $unitID = $data['cid']; $userID = $data['uid']; $start = $data['start']; $end = $data['end']; // get the unit object $unitModel = new RM_Units(); $unit = $unitModel->get($unitID); // convert the date selection to a period object $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($start)), new RM_Date(strtotime($end))); // check if the dates are allowed $reservationModel = new RM_ReservationDetails(); $currentReservationCount = $reservationModel->getReservationCount($unit, $periodObj); if ($currentReservationCount > 0) { return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservations.Edit', 'InvalidSelection'))); die; } $unitDetails = null; // reset the unit array for safe keeping $unitDetails = array(new RM_Reservation_Details($unit, $periodObj, new RM_Reservation_Persons())); $userModel = new RM_Users(); $user = $userModel->find($userID)->current(); // get the "system user" // get a reservation ID $reservationID = RM_Reservations::createReservationID(); $reservationModel = new RM_Reservations(); $result = $reservationModel->insertNewReservation($user, $unitDetails, 0, 1, $reservationID); if (!$result) { return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('Admin.Reservation.Edit', 'ServerError'))); } else { // mark the new block as paid $reservation = $reservationModel->find($reservationID)->current(); if ($userID === "") { $reservationModel->markPaid($reservation); } $idArray = explode("-", $reservationID); $id = (int) $idArray[1]; // check time $ad = true; // all day $starttime = explode(" ", $start); if ($starttime[1] !== "00:00:00") { $ad = false; } $endtime = explode(" ", $end); if ($endtime[1] !== "00:00:00") { $ad = false; } return array('data' => array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => array("id" => $id, "cid" => $unitID, "uid" => (int) $userID, "title" => $reservationID, "start" => $start, "end" => $end, "ad" => $ad))); } }
/** * Returns all saved reservation detail rows * * @return Zend_Db_Table_Rowset_Abstract */ public function getDetails() { $model = new RM_ReservationDetails(); return $model->getAllByReservation($this); }
/** * Return JSON data for the chart * * @return string */ function getData() { $config = new RM_Config(); $units = $this->_getUnits(); $datetimes = $this->_getDatetimes(); $reservationDetailsModel = new RM_ReservationDetails(); // for fusion charts we need xml, so the data needs to be formatted // so that the json data can render the xml using an xtemplate. // we need:- // array dates containing all dates of the period we need to chart. // array units containing 'name', 'color', array: 'data' containing the unit reservation count for each period $jsonSeries = new stdClass(); $jsonDates = new stdClass(); $feildsArray = array(); $jsonSeriesArray = array(); $jsonChartDataArray = array(); $feildsArray[] = 'date'; // this loop, loops through the units once to get the series data foreach ($units as $unit) { $feildsArray[] = 'unit' . $unit->getId(); $jsonSeries->yField = 'unit' . $unit->getId(); $jsonSeries->displayName = $unit->name; $jsonSeries->type = 'line'; // the graph type $jsonSeries->style = '{color: 0x' . $unit->color . '}'; // the graph type $jsonSeriesArray[] = clone $jsonSeries; } // this loop, loops through all dates and gets the data for each period for ($i = 0; $i < count($datetimes) - 1; $i++) { // get the date $date = $config->convertDates($datetimes[$i], RM_Config::PHP_DATEFORMAT, RM_Config::HUMAN_MONTH_DATEFORMAT); $chartData = array(); $chartData['date'] = $date; // loop through each unit foreach ($units as $unit) { $SdateParts = explode("-", $datetimes[$i]); $startDatetimes = mktime(0, 0, 0, (int) $SdateParts[1], (int) $SdateParts[2], (int) $SdateParts[0]); // set the endDatetimes to the last day of the month $EdateParts = explode("-", $datetimes[$i + 1]); $endDatetimes = mktime(0, 0, 0, (int) $EdateParts[1], (int) $SdateParts[2], (int) $EdateParts[0]); //mktime($hour, $minute, $second, $month, $day, $year) $period = new RM_Reservation_Period(new RM_Date($datetimes[$i]), new RM_Date($datetimes[$i + 1])); $count = $reservationDetailsModel->getReservationCount($unit, $period); $chartData['unit' . $unit->getId()] = $count; } //$chartData->units = $dataArray; $jsonChartDataArray[] = $chartData; } $returnData = new stdClass(); // fields: array containing all the fields ie: 'date', 'unit1', 'unit2', 'unit3' // // series: array containing objects for each series item:- // type: 'line',displayName: 'Unit 1',yField: 'unit1',style: {color:0x99BBE8} // note yField = the field name. // // data should contain the data:- // data: [ // {date:'Jul 07', unit1: 9, unit2: 11, unit3: 4}, // {date:'Aug 07', unit1: 5, unit2: 0, unit3: 3}, // {date:'Sep 07', unit1: 4, unit2: 0, unit3: 4}, // {date:'Oct 07', unit1: 8, unit2: 5, unit3: 5}, // {date:'Nov 07', unit1: 4, unit2: 6, unit3: 6}, // {date:'Dec 07', unit1: 0, unit2: 8, unit3: 7}, // {date:'Jan 08', unit1: 0, unit2: 11, unit3: 0}, // {date:'Feb 08', unit1: 8, unit2: 15, unit3: 7} // ] $returnData->fields = $feildsArray; $returnData->series = $jsonSeriesArray; $returnData->data = $jsonChartDataArray; return $returnData; }
public function calculateJsonAction() { $value = $this->_getParam('value'); if ($value === null) { return array('data' => array('success' => false)); } $extraID = $this->_getParam('extra_id'); if ($extraID === null) { return array('data' => array('success' => false)); } $extrasModel = new RM_Extras(); $extra = $extrasModel->find($extraID)->current(); if ($extra === null) { return array('data' => array('success' => false)); } $reservationDetailID = $this->_getParam('detail_id'); if ($reservationDetailID == null) { return array('data' => array('success' => false)); } $reservationDetailsModel = new RM_ReservationDetails(); $reservationDetail = $reservationDetailsModel->find($reservationDetailID)->current(); if ($reservationDetail == null) { return array('data' => array('success' => false)); } $config = new RM_Config(); $currencySymbol = $config->getValue('rm_config_currency_symbol'); // calculate the tax due on the extra... $extraSubTotal = $extra->calculate($reservationDetail); // 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($reservationDetail->findUnit(), $periodObj, $persons, array()); return array('data' => array('success' => true, 'value' => $currencySymbol . $extraSubTotal * $value)); }
/** * Returns the list data for the Unit Assignment Grid. * * This creates a JS variable containing the list configuration/setup for * the reservation list. This is implicated in list.js * * @deprecated * @param request id the reservation id. * @param request type if this is a new or existing reservation. * @param request start list start used for pagenation * @param request limit list limit used for pagenation * @param request sort list sort parameter * @param request dir list direction Asc/desc * @param request filter an array of any filters applied * @return json information required to configure unit selection grid. */ public function listunitsJsonAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); $offset = $this->_getParam('start'); $count = $this->_getParam('limit'); $sort = $this->_getParam('sort', 'id'); $direction = $this->_getParam('dir', 'DESC'); $language = $this->_translate->getAdapter()->getLocale(); $order = $sort . ' ' . $direction; $dao = new RM_ReservationDetails(); if ($type == "new") { $unitTypeDAO = new RM_UnitTypes(); $unitType = $unitTypeDAO->find('1')->current(); $details = $dao->getAll($unitType, $order, $count, $offset, $language, $filters)->toArray(); $total = $dao->getAll($unitType, $order, null, null, $language, $filters)->count(); } else { $reservationDAO = new RM_Reservations(); $reservation = $reservationDAO->find($id)->current(); $total = $dao->fetchAllByReservation($reservation, $order, null, null, $language)->count(); $details = $dao->fetchAllByReservation($reservation, $order, $count, $offset, $language)->toArray(); } $json = new stdClass(); $json->total = $total; $json->data = $details; return array('data' => $json); }
/** * Checks if in system exists any reservation with this unitID * * @param int $unitID unit primary key value * @return bool */ public function isReserved($unitID) { $unitModel = new RM_Units(); $unit = $unitModel->find($unitID)->current(); if ($unit == null) { return false; } $model = new RM_ReservationDetails(); $details = $model->fetchAllBy($unit); return count($details) > 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; }