コード例 #1
0
ファイル: Extras.php プロジェクト: laiello/resmania
 /**
  * Recalculate all for reservation, after some of the unit details has been changed
  *
  * @abstract
  * @param RM_Reservation_Row $reservation
  * @return bool
  */
 function recalculate(RM_Reservation_Row $reservation)
 {
     $summaryModel = new RM_ReservationSummary();
     $extrasModel = new RM_Extras();
     $details = $reservation->getDetails();
     foreach ($details as $detail) {
         $summaryRows = $summaryModel->fetchByReservationDetail($detail);
         foreach ($summaryRows as $summaryRow) {
             if ($summaryRow->type == self::SUMMARY_TYPE) {
                 $extra = $extrasModel->find($summaryRow->row_id)->current();
                 if ($extra == null) {
                     //IF this is a deprecated - total value remains the same
                     continue;
                 }
                 $detailsObj = $detail->transform();
                 if ($detailsObj instanceof RM_Reservation_Details) {
                     $summaryRow->total_amount = -$extra->calculate($detailsObj) * $summaryRow->value;
                     $summaryRow->save();
                 } else {
                     RM_Log::toLog("Extras Encountered Issues: " . print_r($detailsObj, true));
                 }
             }
         }
     }
 }
コード例 #2
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);
 }
コード例 #3
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));
 }
コード例 #4
0
ファイル: Taxes.php プロジェクト: laiello/resmania
 /**
  * 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;
 }
コード例 #5
0
ファイル: Row.php プロジェクト: laiello/resmania
 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();
 }
コード例 #6
0
ファイル: Reservations.php プロジェクト: laiello/resmania
 /**
  * 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);
 }