/** * this returns the saved price information for a reservation * * @param string $reservationID * @return object a complete price breakdown. */ public function getPrice($reservationID) { // TODO: we will need to add code to dynamically check modules and plugins that // have code that adds prices/charges in order to dynamcially check any saved // prices that have been charged to customers if (!isset($reservationID)) { return false; } $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); $priceObj = new stdClass(); $priceObj->tax = RM_Environment::getInstance()->getTaxSystem()->getTotalTaxes($reservation); $priceObj->total = $reservation->getTotalPrice(); $priceObj->subtotal = $priceObj->total - $priceObj->tax; return $priceObj; }
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); }
protected function _assign(Dwoo_Data $data) { $details = $this->_eventData->getAllDetails(); $reservationID = $this->_eventData->getReservationID(); $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); $arrayDetails = array(); foreach ($details as $detail) { $arrayDetails[] = array('unit' => $detail->getUnit()->toArray(), 'period' => (array) $detail->getPeriod(), 'periodtime' => (array) $detail->getPeriod(true), 'persons' => $detail->getPersons(), 'total' => $detail->getTotal()); } // total paid and total due $billing = new RM_Billing(); $priceCharges = $billing->getPrice($reservationID); $billingArray['tax'] = $priceCharges->tax; $billingArray['paid'] = $billing->getPaymentsTotal($reservation); $billingArray['due'] = $priceCharges->total; $billingArray['confirmed'] = $reservation->confirmed ? $translate->_('MessageYes') : $translate->_('MessageNo'); $data->assign('details', $arrayDetails); $data->assign('reservation_id', $this->_eventData->getReservationID()); return $data; }
protected function _assign(Dwoo_Data $data) { $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN); $locationsDAO = new RM_Locations(); $reservationID = $this->_eventData->getReservationID(); $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($reservationID)->current(); // reservation details $details = $this->_eventData->getAllDetails(); $arrayDetails = array(); foreach ($details as $detail) { $unit = $detail->getUnit()->toArray(); $period = $detail->getPeriod()->toArray(); $periodWithTime = $detail->getPeriod()->toArray(true); $location = $locationsDAO->fetchByUnit($unit['id'])->toArray(); $extrasForTemplate = array(); $extras = $detail->getExtras(); foreach ($extras as $extra) { $extrasForTemplate[] = $extra->toArray(); } $arrayDetails[] = array('unit' => $unit, 'locationInfo' => isset($location[0]) ? $location[0] : '', 'period' => $period, 'periodtime' => $periodWithTime, 'persons' => $detail->getPersons()->getAll(), 'total' => $detail->getTotal(), 'extras' => $extrasForTemplate); } // total paid and total due $billing = new RM_Billing(); $priceCharges = $billing->getPrice($reservationID); $billingArray['tax'] = $priceCharges->tax; $billingArray['paid'] = $billing->getPaymentsTotal($reservation); $billingArray['due'] = $priceCharges->total; $billingArray['confirmed'] = $reservation->confirmed ? $translate->_('MessageYes') : $translate->_('MessageNo'); // return the data to the template $data->assign('extras', $extrasForTemplate); $data->assign('details', $arrayDetails); $data->assign('user', $this->_eventData->getUser()->toArray()); $data->assign('reservation_id', $reservationID); $data->assign('billing', $billingArray); return $data; }
/** * 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))); } }
/** * Replace all placeholders with information from current made reservations * * @param RM_Reservation_Manager $manager * @param string $template * @return */ private function _parseCompleteTemplate(RM_Reservation_Manager $manager, $template) { $data = new Dwoo_Data(); $reservationModel = new RM_Reservations(); $reservation = $reservationModel->find($manager->getReservationID())->current(); $summaryModel = new RM_ReservationSummary(); $unitModel = new RM_Units(); $details = $reservation->getDetails(); $arrayDetails = array(); foreach ($details as $detailRow) { $detail = $detailRow->transform(); $unitArray = $detail->getUnit()->toArray(); $periodArray = $detail->getPeriod()->toArray(); $periodArrayWithTime = $detail->getPeriod()->toArray(true); $personsArray = $detailRow->getPersons(); //$unitID = $detail->getUnit()->getId(); $unitID = $unitArray['id']; $unit = $unitModel->get($unitID); $locationModel = new RM_Locations(); $location = $locationModel->fetchByUnit($unitID)->current(); $arrayDetails[] = array('unit' => $unit->toArray(), 'period' => $periodArray, 'periodtime' => $periodArrayWithTime, 'persons' => $personsArray, 'summary' => $summaryModel->fetchByReservationDetail($detailRow)->toArray(), 'location' => $location !== null ? $location->toArray() : $locationModel->createRow()->toArray()); } $data->assign('details', $arrayDetails); $data->assign('user', $manager->getUser()->toArray()); $reservationArray = $reservation->toArray(); $reservationArray['confirmed'] = $reservation->isPaid() ? $this->_translate->_('MessageYes') : $this->_translate->_('MessageNo'); $reservationArray['total'] = $reservation->getTotalPrice(); $reservationArray['paid'] = $reservation->getTotalPaid(); $reservationArray['due'] = $reservationArray['total'] - $reservationArray['paid']; $data->assign('reservation', $reservationArray); $dwooTemplate = new Dwoo_Template_String($template); $dwoo = new Dwoo(); return $dwoo->get($dwooTemplate, $data); }
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); }
public function ipnAction() { $this->_withoutView(); $provider = new RM_Plugin_PayPal(); $provider->validateIPN(); RM_Log::toLog("PayPal ipnAction Called"); if ($provider->ipnData['payment_status'] == "Completed" || $provider->ipnData['payment_status'] == "Pending") { RM_Log::toLog("PayPal payment status: " . $provider->ipnData['payment_status']); if (str_word_count($provider->ipnData['invoice'], 0, "RM-") > 0) { $bookingref = ltrim($provider->ipnData['invoice'], "RM-"); } else { $bookingref = $provider->ipnData['invoice']; } RM_Log::toLog("Booking ref passed back from PayPal: " . $bookingref); $model = new RM_Reservations(); $reservation = $model->find($bookingref)->current(); RM_Log::toLog("Reservation Record ID: " . $reservation->id); $model->confirm($reservation); RM_Log::toLog("Confirmed Updated"); $model->inProgressComplete($reservation); RM_Log::toLog("InProgress Marker Updated"); // save the total // we have a problem here, when this action is called it is called // from the paypal.com server. The session is not the same so saving to it // is impossible. I think we need to pass to PayPal the 'custom' parameter // this could contain something like the session id, however I am not // sure if it's possible to update the data in a session with a session // id? //$manager = RM_Reservation_Manager::getInstance(); $total_paid = $provider->ipnData['mc_gross']; RM_Log::toLog("Total Passed back from PayPal: " . $total_paid); //$manager->setPaymentTotal($total_paid); // save the total incase we need it later. //if (!$total_paid) $this->_redirect('Reservations', 'notcomplete'); // this handles if the total amount is null'd $billingModel = new RM_Billing(); $billingRow = $billingModel->createRow(); $billingRow->reservation_id = $bookingref; $billingRow->total_paid = $total_paid; $billingID = $billingRow->save(); RM_Log::toLog("Billing Updated"); // TODO: I can't get thsi working.. // save the payment information $billingPaymentsModel = new RM_BillingPayments(); $billingPaymentRow = $billingPaymentsModel->createRow(); $billingPaymentRow->id = $billingID; $billingPaymentRow->provider = "PayPal"; $billingPaymentRow->transaction_id = $provider->ipnData['txn_id']; $billingPaymentRow->status = $provider->ipnData['payment_status']; $billingPaymentRow->total = $provider->ipnData['mc_gross']; $billingPaymentRow->transaction_date = Date("Y-m-d"); $billingPaymentRow->save(); RM_Log::toLog("Billing Payments Updated"); // TODO: if the IPN is successful then we need to set the in_progress flag to 0 // this is also done in the reservation controller on success we have to do it here also // as it is possible the customer may not return to the site via the payment provider // return URL in this case the in_progress flag will never be updated that's why we // need to do this here also // I need to ask Valentin about a standard method for this. // TODO: we should also record other information such as the transaction id // however this can be added later. } }
/** * This is used for the reservation list to toggle read/unread */ public function readmarkerJsonAction() { $ids = $this->_getParam('ids', array()); $state = $this->_getParam('state'); $model = new RM_Reservations(); foreach ($ids as $id) { $reservation = $model->find($id)->current(); if ($reservation == null) { continue; } $reservation->is_read = $state; $reservation->save(); } return array('data' => array('success' => true)); }