Ejemplo n.º 1
0
 /**
  * Returns total price for reservation with only options that are
  * connected to reservation itself. It could be only '-' if there is only a discount for example
  *
  * @return float
  */
 private function _getTotalPrice()
 {
     $total = 0;
     $summaryModel = new RM_ReservationSummary();
     $summaryRows = $summaryModel->fetchByReservation($this);
     foreach ($summaryRows as $row) {
         $total += $row->total_amount;
     }
     return $total;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * Assign extras to reservation
  *
  * @param RM_Reservation_Details $detail
  * @param RM_Reservation_Details_Row $detailRow
  * @return void
  */
 public function assign(RM_Reservation_Details $detail, RM_Reservation_Details_Row $detailRow)
 {
     $extras = $detail->getExtras();
     foreach ($extras as $extra) {
         if ($extra instanceof RM_Extras_Object) {
             $summaryModel = new RM_ReservationSummary();
             $summaryModel->insert(array('row_id' => $extra->getID(), 'type' => self::SUMMARY_TYPE, 'reservation_detail_id' => $detailRow->id, 'value' => $extra->getValue(), 'total_amount' => $extra->getPrice(), 'name' => $extra->getName()));
             // insert the extra tax
             $summaryModel->insert(array('row_id' => $extra->getID(), 'type' => self::SUMMARY_TYPE_TAX, 'reservation_detail_id' => $detailRow->id, 'value' => $extra->getValue(), 'total_amount' => $extra->getTax(), 'name' => "Extras Tax"));
         }
     }
 }
Ejemplo n.º 5
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));
 }
Ejemplo n.º 6
0
 /**
  * Return total value of saved taxes for reservation
  *
  * @param RM_Reservation_Row $reservation
  * @return float
  */
 function getTotalTaxes(RM_Reservation_Row $reservation)
 {
     $total = 0;
     $details = $reservation->getDetails();
     $summaryModel = new RM_ReservationSummary();
     foreach ($details as $detail) {
         $summaryRows = $summaryModel->fetchByReservationDetail($detail);
         foreach ($summaryRows as $summaryRow) {
             if ($summaryRow->type == self::SUMMARY_TYPE) {
                 $total += $summaryRow->total_amount;
             }
         }
     }
     return $total;
 }
Ejemplo n.º 7
0
 public function delete()
 {
     //Delete all reservation summary that are assigned to it
     $model = new RM_ReservationSummary();
     $rows = $model->fetchByReservationDetail($this);
     foreach ($rows as $row) {
         $row->delete();
     }
     return parent::delete();
 }
Ejemplo n.º 8
0
 /**
  * Method that parsed invoice template and returns string
  *
  * All variable that parsed into invoice.pthml template
  * $reservation:
  * $reservation.id
  * $reservation.user_id
  * $reservation.confirmed (Yes, No - translated)
  * $reservation.is_read (Yes, No - translated)
  * $reservation.creation_datetime (In MySQL format: Y-m-d H:m:s)
  * $reservation.modified_datetime (In MySQL format: Y-m-d H:m:s)
  * $reservation.notes
  * $reservation.tax
  * $reservation.paid
  * $reservation.due
  *
  * $customer:
  * $customer.id
  * $customer.title (Translated)
  * $customer.first_name
  * $customer.last_name
  * $customer.address1
  * $customer.address2
  * $customer.state
  * $customer.city
  * $customer.postcode
  * $customer.country
  * $customer.telephone
  * $customer.mobile
  * $customer.email
  * $customer.username
  *
  * $details each detail is an $element:
  * $element.reservation_id
  * $element.unit_id
  * $element.start_datetime (In MySQL format: Y-m-d H:m:s)
  * $element.end_datetime (In MySQL format: Y-m-d H:m:s)
  * $element.total_price
  * $element.unit.id
  * $element.unit.rating (number)
  * $element.unit.published (Yes, No - translated)
  * $element.unit.color (hex color)
  * $element.unit.(all language db field names that are belong to unit type, for example: name, summary, description)
  *
  * $text: all text constants in section 'Admin.Invoice' in languages file, for example $text.BookingReference
  *
  * @param RM_Reservation_Row $reservation
  * @return <type>
  */
 public static function getInvoice(RM_Reservation_Row $reservation)
 {
     $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN);
     $data = new Dwoo_Data();
     $data->assign('invoice', array('date' => date('d/m/Y')));
     $config = new RM_Config();
     $data->assign('currencysymbol', $config->getCurrencySymbol());
     //TODO: resmania - we need to add discounts and coupons here
     $reservationArray = $reservation->toArray();
     $billing = new RM_Billing();
     $priceCharges = $billing->getPrice($reservation->id);
     $reservationArray['tax'] = $priceCharges->tax;
     $reservationArray['paid'] = $billing->getPaymentsTotal($reservation);
     $reservationArray['due'] = abs($priceCharges->total - $billing->getPaymentsTotal($reservation));
     $reservationArray['total'] = $priceCharges->total;
     $reservationArray['confirmed'] = $reservation->confirmed ? $translate->_('MessageYes') : $translate->_('MessageNo');
     $reservationArray['is_read'] = $reservation->is_read ? $translate->_('MessageYes') : $translate->_('MessageNo');
     $data->assign('reservation', $reservationArray);
     $text = $translate->getSectionMessages('Common.Invoice');
     $data->assign('text', $text);
     $userModel = new RM_Users();
     $user = $userModel->getByReservation($reservation);
     if ($user == null) {
         $userArray = array();
     } else {
         $userArray = $user->toArray();
         $userArray['title'] = $user->getTitle();
     }
     $data->assign('customer', $userArray);
     $reservationDetailsModel = new RM_ReservationDetails();
     $summaryModel = new RM_ReservationSummary();
     $details = $reservationDetailsModel->getAllByReservation($reservation);
     $arrayDetails = array();
     foreach ($details as $detail) {
         $arrayDetail = $detail->toArray();
         $unit = $detail->findUnit();
         $unitArray = $unit->toArray();
         $unitArray['id'] = $unit->getId();
         $unitArray['published'] = $unitArray->published ? $translate->_('MessageYes') : $translate->_('MessageNo');
         // format the start/end dates
         $arrayDetail['start_datetime'] = $config->convertDates($arrayDetail['start_datetime'], RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT);
         $arrayDetail['end_datetime'] = $config->convertDates($arrayDetail['end_datetime'], RM_Config::PHP_DATEFORMAT, RM_Config::JS_DATEFORMAT);
         // extras
         $reservationDetailsExtra = $summaryModel->fetchByReservationDetail($detail)->toArray();
         foreach ($reservationDetailsExtra as $extra) {
             if ($extra['value'] == 0) {
                 $extra['value'] = "";
             }
             $unitArray['extras'][] = array("name" => $extra['name'], "value" => $extra['value'], "total_amount" => $extra['total_amount']);
         }
         $arrayDetail['unit'] = $unitArray;
         $arrayDetails[] = $arrayDetail;
     }
     $data->assign('details', $arrayDetails);
     $templateFile = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'views', 'admin', 'scripts', 'templates', 'invoice.phtml'));
     $template = new Dwoo_Template_File($templateFile);
     $dwoo = new Dwoo();
     return $dwoo->get($template, $data);
 }