/** * Display the view */ public function display($tpl = null) { // get the data $this->months = $this->get('Months'); $this->month_days = $this->get('MonthDays'); $this->month_start = $this->get('MonthStart'); $this->month_16 = $this->get('Month16'); $this->hotels = $this->get('Hotels'); $this->hotel = $this->get('Hotel'); $this->inventory = $this->get('Inventory'); $this->bookings_in_progress = $this->get('BookingsInProgress'); // filters $this->state = $this->get('State'); // default dates $app = JFactory::getApplication(); $date_format = CHPanelHelper::getDateFormat(JText::_('COM_CHPANEL_LOCALE')); // start & end $this->start = $app->getUserStateFromRequest('com_chpanel.manage.start', 'start', JFactory::getDate()->format($date_format), 'string'); $this->end = $app->getUserStateFromRequest('com_chpanel.manage.end', 'end', JFactory::getDate('+ 1 day')->format($date_format), 'string'); // title $date = new JDate('01-' . $this->state->get('filter.month')); $this->title = $this->hotel ? $this->hotel->title . ' - ' . $date->format('F Y') : $date->format('F Y'); // toolbar CHPanelHelper::getToolbar('manage'); // sidebar $this->sidebar = JHtmlSidebar::render(); // display the view layout parent::display($tpl); }
/** * Update inventory */ public function update() { // get the hotel $hotel = $this->getHotel(); if (!$hotel) { $this->setError(JText::_('COM_CHPANEL_MANAGE_ERROR_HOTEL')); return false; } // prepare check $db = JFactory::getDbo(); $app = JFactory::getApplication(); $date_format = CHPanelHelper::getDateFormat(JText::_('COM_CHPANEL_LOCALE')); // start $start = $app->getUserStateFromRequest('com_chpanel.manage.start', 'start', JFactory::getDate()->format($date_format), 'string'); $date_start = new JDate(CHPanelHelper::correctDateFormat($start)); $this->start_date = $date_start->format('Y-m-d'); // end $end = $app->getUserStateFromRequest('com_chpanel.manage.end', 'end', JFactory::getDate('+ 1 day')->format($date_format), 'string'); $date_end = new JDate(CHPanelHelper::correctDateFormat($end)); $this->end_date = $date_end->format('Y-m-d'); // check dates if (!$this->start_date || !$this->end_date) { $this->setError(JText::_('COM_CHPANEL_MANAGE_ERROR_DATES')); return false; } // check period if ($date_end->format('Ymd') < $date_start->format('Ymd')) { $this->setError(JText::_('COM_CHPANEL_MANAGE_ERROR_DATES')); return false; } // check values $rids = array(); foreach ($hotel->rooms as $room) { if (JRequest::getString('availability_' . $room->id, '', 'post') != '') { $rids[] = $room->id; } if (JRequest::getString('rate_' . $room->id, '', 'post') != '') { $rids[] = $room->id; } } if (!$rids) { $this->setError(JText::_('COM_CHPANEL_MANAGE_ERROR_INVENTORY')); return false; } // set filter_month state JFactory::getApplication()->setUserState('com_chpanel.manage.filter.month', $date_start->format('m-Y')); // get the rooms ids $room_ids = array_unique($rids); // update inventory per room foreach ($room_ids as $room_id) { // get the room default rate foreach ($hotel->rooms as $room) { if ($room->id == $room_id) { $default_rate = $room->rate; } } // get the room current inventory $inventory_rows = $this->getRoomInventory($room_id); // prepare loop dates $date = $date_start->toUnix(); $while_date = $date_start->format('Ymd'); $while_end = $date_end->format('Ymd'); $current_date = $date_start->format('Y-m-d'); // update inventory while ($while_date <= $while_end) { // new object query $row = new stdClass(); // get row values if (JRequest::getString('availability_' . $room_id, '', 'post') != '') { $row->availability = JRequest::getInt('availability_' . $room_id, 0, 'post'); } if (JRequest::getString('rate_' . $room_id, '', 'post') != '') { $row->rate = JRequest::getFloat('rate_' . $room_id, 0, 'post'); } // update or insert inventory row if (isset($inventory_rows[$current_date])) { // update row $row->id = $inventory_rows[$current_date]->id; $db->updateObject('#__chpanel_inventory', $row, 'id'); } else { // default availability, 0 for new rows if (!isset($row->availability)) { $row->availability = 0; } // default rate, room rack rate if (!isset($row->rate)) { $row->rate = $default_rate; } // insert row $row->room_id = $room_id; $row->date = $current_date; $db->insertObject('#__chpanel_inventory', $row); } // update loop conditions $date = strtotime('+1 day', $date); $j_date = JFactory::getDate($date); $while_date = $j_date->format('Ymd'); $current_date = $j_date->format('Y-m-d'); } } // return ok JFactory::getApplication()->enqueueMessage(JText::_('COM_CHPANEL_MANAGE_APPLY_OK')); return true; }
<?php } else { ?> <p class="alert alert-warning"><?php echo JText::_('COM_CHPANEL_PANEL_CHECKINS_NO'); ?> </p> <?php } ?> <div class="clearfix"> <?php $today = JFactory::getDate()->format(CHPanelHelper::getDateFormat(JText::_('COM_CHPANEL_LOCALE'))); $link = JRoute::_('index.php?option=com_chpanel&view=bookings&filter[hotel]=&filter[status]=&filter[state]=&list[fullordering]=a.checkin%20ASC&date=checkin&end=&start=' . $today); ?> <a class="btn btn-small pull-right" href="<?php echo $link; ?> "><?php echo JText::_('COM_CHPANEL_PANEL_VIEW_MORE'); ?> </a> </div> </div> </div>
<?php /** * @package CHPanel * @copyright Copyright (C) CloudHotelier. All rights reserved. * @license GNU GPLv2 <http://www.gnu.org/licenses/gpl.html> * @author Xavier Pallicer <*****@*****.**> */ defined('_JEXEC') or die; JHtml::_('formbehavior.chosen', 'select'); // options $lang = substr(JFactory::getLanguage()->getTag(), 0, 2); $checkfields = JText::_('COM_CHPANEL_ANY_ERROR_CHECKFIELDS'); $weekstart = JText::_('COM_CHPANEL_LOCALE_WEEKSTART'); $dateformat = str_replace('Y', 'yyyy', str_replace('m', 'mm', str_replace('d', 'dd', CHPanelHelper::getDateFormat(JText::_('COM_CHPANEL_LOCALE'))))); $options = array(); $options[] = "checkfields: '{$checkfields}'"; $options[] = "datepicker_format: '{$dateformat}'"; $options[] = "datepicker_lang: '{$lang}'"; $options[] = "datepicker_weekstart: '{$weekstart}'"; JFactory::getDocument()->addScriptDeclaration("window.chpanel_options = {" . implode(",\n", $options) . "};"); // load datepicker JHtml::stylesheet(JUri::base() . 'components/com_chpanel/assets/datepicker/css/datepicker.css'); JHtml::script(JUri::base() . 'components/com_chpanel/assets/datepicker/js/bootstrap-datepicker.js'); if ($lang != 'en') { JHtml::script(JUri::base() . "components/com_chpanel/assets/datepicker/js/locales/bootstrap-datepicker.{$lang}.js"); } // tooltip JHtml::_('bootstrap.tooltip'); ?>