예제 #1
0
 /**
  * @param   request id  unit id
  * @see modules/prices/js/unit_list.js
  * @return 	json    json array informatio in format:
  * {fields: [<view>, <view>, ...]}
  */
 function listJsonAction()
 {
     $unitID = $this->_getParam('id', '');
     $unitModel = new RM_Units();
     $unit = $unitModel->find($unitID)->current();
     $config = new RM_UnitDailyPricesConfig();
     $configObject = new stdClass();
     $configObject->dailyEnabled = $config->fetchValueByUnit($unitID, 'daily_price_enabled');
     $configObject->midweekEnabled = $config->fetchValueByUnit($unitID, 'midweek_days');
     $configObject->monthlyEnabled = $config->fetchValueByUnit($unitID, 'monthly_price_enabled');
     $configObject->weekendEnabled = $config->fetchValueByUnit($unitID, 'weekend_price_enabled');
     //We need all price row columns infor
     $jsonFields = array();
     $rowModel = new RM_DailyPricesColumns();
     $rows = $rowModel->fetchAllEnabled($configObject);
     //$rowModel = new RM_UnitDailyPricesColumns();
     //$rows = $rowModel->getByUnit($unit);
     foreach ($rows as $row) {
         if ($row->admin_view == '') {
             continue;
         }
         $jsonFields[] = $row->admin_view;
     }
     $json = "{            \n            fields : [" . implode(',', $jsonFields) . "]            \n        }";
     return array('data' => $json, 'encoded' => true);
 }
예제 #2
0
파일: Row.php 프로젝트: laiello/resmania
 /**
  * @todo Oh, we really need to remove this method later, so in system should be only RM_Reservation_Details_Row class
  * @return RM_Reservation_Details
  */
 function transform()
 {
     $period = new RM_Reservation_Period(new RM_Date(strtotime($this->start_datetime)), new RM_Date(strtotime($this->end_datetime)));
     $unitModel = new RM_Units();
     $unit = $unitModel->find($this->unit_id)->current();
     return new RM_Reservation_Details($unit, $period, new RM_Reservation_Persons());
 }
 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));
 }
예제 #4
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));
     }
 }
예제 #5
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));
 }
예제 #6
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);
 }
예제 #7
0
 public function reservationUpdate($detail)
 {
     $reservationDetailID = $detail->id;
     if ($reservationDetailID == null) {
         return false;
     }
     $reservationDetailsModel = new RM_ReservationDetails();
     $reservationDetail = $reservationDetailsModel->find($reservationDetailID)->current();
     if ($reservationDetail == null) {
         return false;
     }
     $summaryModel = new RM_ReservationSummary();
     $extrasModel = new RM_Extras();
     $unitObject = new RM_Units();
     $taxSystem = RM_Environment::getInstance()->getTaxSystem();
     $taxes = $taxSystem->getAllTaxes($unitObject->find($reservationDetail->unit_id)->current());
     // 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());
     $extras = $detail->extras;
     foreach ($extras as $extra) {
         $extraRow = $extrasModel->find($extra->id)->current();
         if ($extraRow == null) {
             continue;
         }
         $extraTotal = $extraRow->calculate($reservationDetail);
         $quantity = (int) $extra->value;
         // calculate the taxes
         $taxTotal = 0;
         foreach ($taxes as $tax) {
             $taxTotal = $taxTotal + $tax->calculate($extraTotal, $fullReservationDetails);
         }
         // multiply by the selection
         $extraTotal = $quantity * $extraTotal;
         $summaryRow = $summaryModel->getByDetail($reservationDetail, RM_Module_Extras::SUMMARY_TYPE, $extra->id);
         // tax
         $summaryTaxRow = $summaryModel->getByDetail($reservationDetail, RM_Module_Extras::SUMMARY_TYPE_TAX, $extra->id);
         // remove the row if the quantity is zero
         if ($summaryRow !== null && $quantity === 0) {
             $delResult = $summaryModel->delete("reservation_detail_id='" . $reservationDetail->id . "' AND type='" . RM_Module_Extras::SUMMARY_TYPE . "' AND row_id='" . $extra->id . "'");
             if ($delResult) {
                 // delete the tax row
                 $summaryTaxRow->delete("reservation_detail_id='" . $reservationDetail->id . "' AND type='" . RM_Module_Extras::SUMMARY_TYPE_TAX . "' AND row_id='" . $extra->id . "'");
             }
             continue;
         }
         if ($summaryRow !== null) {
             $summaryRow->value = $quantity;
             $summaryRow->total_amount = $extraTotal;
             $summaryRow->save();
         } else {
             if ($quantity > 0) {
                 $summaryRow = $summaryModel->createRow(array('reservation_id' => null, 'reservation_detail_id' => $reservationDetail->id, 'type' => RM_Module_Extras::SUMMARY_TYPE, 'row_id' => $extra->id, 'value' => $quantity, 'total_amount' => $extraTotal, 'name' => $extraRow->getName(RM_Environment::getInstance()->getLocale())));
                 $summaryRow->save();
             }
         }
         // tax
         if ($summaryTaxRow !== null) {
             $summaryTaxRow->value = $quantity;
             $summaryTaxRow->total_amount = $taxTotal * $quantity;
             $summaryTaxRow->save();
         } else {
             if ($quantity > 0) {
                 $summaryTaxRow = $summaryModel->createRow(array('reservation_id' => null, 'reservation_detail_id' => $reservationDetail->id, 'type' => RM_Module_Extras::SUMMARY_TYPE_TAX, 'row_id' => $extra->id, 'value' => $quantity, 'total_amount' => $taxTotal * $quantity, 'name' => "Extras Tax"));
                 $summaryTaxRow->save();
             }
         }
     }
     return true;
 }
예제 #8
0
 /**
  * Invoked from Edit Reservations form via an AJAX request (edit.js) and is used to Update the Reservation
  *
  * This copies the data from the temp tables back to the live table and destroys the temp reservation
  * The reason we have a temp table for reservations and reservation details is that the we need to store
  * the ajax requests temporarilly until the user is ready to save and commit the reservation. If they
  * abandon the reservation then the temp data is either re-used when the reservation is re-edited or
  * refreshed. This allows some freedom to the user to change the reservation but to also cancel out if
  * they do not want to commit changes.
  *
  * @param  	request id  the reservation is linked by the id of the reservation (not the reference_id, this is just for the admins/users information)
  * @return 	json    boolean (true if success)
  */
 public function updateJsonAction()
 {
     $reservationJson = Zend_Json::decode($this->_getParam('reservation', "[]"));
     if (count($reservationJson) == 0) {
         return array('data' => array('success' => false));
     }
     $reservationModel = new RM_Reservations();
     $reservation = $reservationModel->find($reservationJson['id'])->current();
     if ($reservation == null) {
         return array('data' => array('success' => false));
     }
     foreach ($reservationJson as $fieldName => $value) {
         $reservation->{$fieldName} = $value;
     }
     $reservation->save();
     $reservationDetailsModel = new RM_ReservationDetails();
     //Delete all disabled reservation details
     $deletedUnitIDs = Zend_Json::decode($this->_getParam('deleted_unit_ids', "[]"));
     $unitModel = new RM_Units();
     foreach ($deletedUnitIDs as $unitID) {
         $unit = $unitModel->find($unitID)->current();
         if ($unit == null) {
             continue;
         }
         $details = $reservationDetailsModel->fetchAllBy($unit, $reservation);
         foreach ($details as $detail) {
             $detail->delete();
         }
     }
     $detailsJson = Zend_Json::decode($this->_getParam('details', "[]"));
     foreach ($detailsJson as $detailJson) {
         if (in_array($detailJson['unit_id'], $deletedUnitIDs)) {
             continue;
         }
         $unit = $unitModel->find($detailJson['unit_id'])->current();
         $detail = $reservationDetailsModel->fetchAllBy($unit, $reservation)->current();
         /**
          * Other info management. This code allows other information to be handled
          * by the price system. Edit.js on save will pass through an array of
          * Other Info items these must be decoded and must replace the 'otherinfo'
          * index in the detail array.
          *
          * otherinfo is defined in the edit.js in the return param's however this
          * is just a generic placeholder to pass the data as this could be anything
          *
          * for example if need to pass board_type which is used by the hospitality
          * then we pass this on the otherinfo param as a json array. leaving the otherinfo
          * index in the array will cause the update to fail as this column will not
          * be found. So we read in the json array then add the keys for the
          * other items then finally remove the other info index.
          *
          * ie: if board_type = 'hb' and extra_bed = '1' are passed these would be
          * in the otherinfo json and will be added to the detail array then the
          * otherinfo value will be removed.
          */
         $otherInfo = Zend_Json::decode($detailJson['otherinfo']);
         // zend json decode puts the array inside another array so we have to return i0.
         if (!empty($otherInfo)) {
             foreach ($otherInfo[0] as $key => $value) {
                 $detailJson[$key] = $value;
                 unset($detailJson['otherinfo']);
             }
         } else {
             // if it's not passed remove it as some
             // price systems my not have this row
             unset($detailJson['otherinfo']);
         }
         // others systems processing (not to be confused with otherInfo
         $otherPriceTotal = 0;
         $othersSystems = Zend_Json::decode($this->_getParam('other_systems', "[]"));
         foreach ($othersSystems as $system) {
             $systemName = $system['systemClassName'];
             // this will be the module/plugin class for updating
             $systemClassName = "RM_Module_" . $systemName;
             $lowercaseSystemClassName = strtolower($systemName);
             $dataArray['id'] = $detail->id;
             foreach ($system['data'] as $data) {
                 $dataArray[$data['name']] = $data['value'];
             }
             $otherModel = new $systemClassName();
             $otherModel->updateOtherData($dataArray);
             $othersNewPrice = $otherModel->getPrice($dataArray);
             $reservationSummaryModel = new RM_ReservationSummary();
             $reservationSummaryRows = $reservationSummaryModel->fetchByReservationDetail($detail, $lowercaseSystemClassName)->current();
             $reservationSummaryRows->total_amount = $othersNewPrice['price'];
             $reservationSummaryRows->save();
         }
         // others system complete
         if ($detail == null) {
             $detail = $reservationDetailsModel->createRow($detailJson);
         } else {
             foreach ($detailJson as $key => $value) {
                 $detail->{$key} = $value;
             }
         }
         $period = new RM_Reservation_Period(new RM_Date(strtotime($detail->start_datetime)), new RM_Date(strtotime($detail->end_datetime)));
         $persons = new RM_Reservation_Persons(array("adults" => $detail->adults, "children" => $detail->children, "infants" => $detail->infants));
         // 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);
             }
         }
         $information = new RM_Prices_Information($unit, $period, $persons, $otherInfo[0]);
         $priceSystem = RM_Environment::getInstance()->getPriceSystem();
         try {
             $detail->total_price = $priceSystem->getTotalUnitPrice($information);
         } catch (Exception $e) {
             $detail->total_price = 0;
         }
         //$detail->total_price += $otherPriceTotal;
         $detail->save();
     }
     //We need to recalculate all information that was saved to reservation
     $reservation->recalculate();
     return array('data' => array('success' => true));
 }
예제 #9
0
 public function deleteJsonAction()
 {
     $dao = new RM_Units();
     $unitIDs = $this->_getParam('ids', array());
     foreach ($unitIDs as $uid) {
         $unit = $dao->find($uid)->current();
         if ($unit !== null) {
             $dao->deleteRow($unit);
         }
     }
     return array('data' => array('success' => true));
 }
예제 #10
0
파일: Sorter.php 프로젝트: laiello/resmania
 /**
  * @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;
 }
예제 #11
0
파일: Units.php 프로젝트: laiello/resmania
 /**
  * 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;
 }
예제 #12
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;
 }