PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.6
VikBooking Hotel Booking Engine & PMS v1.8.6
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / views / orders / view.html.php

view.html.php in VikBooking Hotel Booking Engine & PMS 1.8.6, at admin/views/orders/view.html.php

293 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 // import Joomla view library
14 jimport('joomla.application.component.view');
15
16 class VikBookingViewOrders extends JViewVikBooking
17 {
18 public function display($tpl = null)
19 {
20 // Set the toolbar
21 $this->addToolBar();
22
23 if (!JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking')) {
24 VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 }
26
27 $rows = "";
28 $navbut = "";
29 $app = JFactory::getApplication();
30 $dbo = JFactory::getDbo();
31 if (file_exists(VCM_ADMIN_PATH.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'vcm-channels.css')) {
32 $document = JFactory::getDocument();
33 $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vcm-channels.css');
34 }
35 $pconfirmnumber = VikRequest::getString('confirmnumber', '', 'request');
36 $pidroom = $app->getUserStateFromRequest("vbo.orders.idroom", 'idroom', 0, 'int');
37 $pchannel = $app->getUserStateFromRequest("vbo.orders.channel", 'channel', '', 'string');
38 $pcust_id = $app->getUserStateFromRequest("vbo.orders.cust_id", 'cust_id', 0, 'int');
39 $pdatefilt = $app->getUserStateFromRequest("vbo.orders.datefilt", 'datefilt', 0, 'int');
40 $pdatefiltfrom = $app->getUserStateFromRequest("vbo.orders.datefiltfrom", 'datefiltfrom', '', 'string');
41 $pdatefiltto = $app->getUserStateFromRequest("vbo.orders.datefiltto", 'datefiltto', '', 'string');
42 $pcategory_id = $app->getUserStateFromRequest("vbo.orders.category_id", 'category_id', 0, 'int');
43 $dates_filter = '';
44 if (!empty($pdatefilt) && (!empty($pdatefiltfrom) || !empty($pdatefiltto))) {
45 $dates_filter_field = '`o`.`ts`';
46 if ($pdatefilt == 2) {
47 $dates_filter_field = '`o`.`checkin`';
48 } elseif ($pdatefilt == 3) {
49 $dates_filter_field = '`o`.`checkout`';
50 }
51 $dates_filter_clauses = array();
52 if (!empty($pdatefiltfrom)) {
53 $dates_filter_clauses[] = $dates_filter_field.'>='.VikBooking::getDateTimestamp($pdatefiltfrom, '0', '0');
54 }
55 if (!empty($pdatefiltto)) {
56 $dates_filter_clauses[] = $dates_filter_field.'<='.VikBooking::getDateTimestamp($pdatefiltto, 23, 60);
57 }
58 $dates_filter = implode(' AND ', $dates_filter_clauses);
59 }
60 $pstatus = $app->getUserStateFromRequest("vbo.orders.status", 'status', 0, 'string');
61 $status_filter = !empty($pstatus) && in_array($pstatus, array('confirmed', 'standby', 'cancelled')) ? "`o`.`status`='".$pstatus."' AND `o`.`closure`=0" : '';
62 if (empty($status_filter) && !empty($pstatus)) {
63 if ($pstatus == 'closure') {
64 $status_filter = "`o`.`closure`=1";
65 } elseif (in_array($pstatus, array('checkedin', 'checkedout', 'noshow', 'none'))) {
66 switch ($pstatus) {
67 case 'checkedin':
68 $status_filter = "`o`.`checked`=1";
69 break;
70 case 'checkedout':
71 $status_filter = "`o`.`checked`=2";
72 break;
73 case 'noshow':
74 $status_filter = "`o`.`checked` < 0";
75 break;
76 case 'none':
77 $status_filter = "`o`.`checked`=0 AND `o`.`closure`=0";
78 break;
79 default:
80 break;
81 }
82 } elseif (in_array($pstatus, ['request', 'inquiry', 'overbooking'])) {
83 $status_filter = "`o`.`type`=" . $dbo->quote($pstatus);
84 } elseif ($pstatus == 'split_stay') {
85 $status_filter = "`o`.`split_stay`=1";
86 }
87 }
88 $pidpayment = $app->getUserStateFromRequest("vbo.orders.idpayment", 'idpayment', 0, 'int');
89 $payment_filter = '';
90 if (!empty($pidpayment)) {
91 $payment_filter = "`o`.`idpayment` LIKE '".$pidpayment."=%'";
92 }
93 $ordersfound = false;
94 $lim = $app->getUserStateFromRequest("com_vikbooking.limit", 'limit', $app->get('list_limit'), 'int');
95 $lim0 = $app->getUserStateFromRequest("vbo.orders.limitstart", 'limitstart', 0, 'int');
96 $session = JFactory::getSession();
97 $pvborderby = VikRequest::getString('vborderby', '', 'request');
98 $pvbordersort = VikRequest::getString('vbordersort', '', 'request');
99 $validorderby = array('id', 'ts', 'days', 'checkin', 'checkout', 'total');
100 $orderby = $session->get('vbViewOrdersOrderby', 'ts');
101 $ordersort = $session->get('vbViewOrdersOrdersort', 'DESC');
102 if (!empty($pvborderby) && in_array($pvborderby, $validorderby)) {
103 $orderby = $pvborderby;
104 $session->set('vbViewOrdersOrderby', $orderby);
105 if (!empty($pvbordersort) && in_array($pvbordersort, array('ASC', 'DESC'))) {
106 $ordersort = $pvbordersort;
107 $session->set('vbViewOrdersOrdersort', $ordersort);
108 }
109 }
110
111 $q = "SELECT `id`,`name` FROM `#__vikbooking_rooms` ORDER BY `name` ASC;";
112 $dbo->setQuery($q);
113 $allrooms = $dbo->loadAssocList();
114
115 if (!empty($pconfirmnumber)) {
116 /**
117 * We allow looking for a specific ID, OTAID, Coupon code etc.. by using syntaxes like "id: 500"
118 */
119 $q = $dbo->getQuery(true)->select('SQL_CALC_FOUND_ROWS `o`.*');
120 $q->from($dbo->qn('#__vikbooking_orders', 'o'));
121 $q->where(1);
122
123 if (stripos($pconfirmnumber, 'id:') === 0) {
124 // search by ID or OTA ID
125 $seek_parts = explode('id:', $pconfirmnumber);
126 $seek_value = trim($seek_parts[1]);
127 $q->andWhere([
128 $dbo->qn('o.id') . ' = ' . $dbo->q($seek_value),
129 $dbo->qn('o.idorderota') . ' = ' . $dbo->q($seek_value),
130 ], $glue = 'OR');
131 } elseif (stripos($pconfirmnumber, 'otaid:') === 0) {
132 // search by OTA Booking ID
133 $seek_parts = explode('otaid:', $pconfirmnumber);
134 $seek_value = trim($seek_parts[1]);
135 $q->where($dbo->qn('o.idorderota') . ' = ' . $dbo->q($seek_value));
136 } elseif (stripos($pconfirmnumber, 'coupon:') === 0) {
137 // search by coupon code
138 $seek_parts = explode('coupon:', $pconfirmnumber);
139 $seek_value = trim($seek_parts[1]);
140 $q->where($dbo->qn('o.coupon') . ' LIKE ' . $dbo->q("%{$seek_value}%"));
141 } elseif (stripos($pconfirmnumber, 'name:') === 0) {
142 // search by customer nominative
143 $seek_parts = explode('name:', $pconfirmnumber);
144 $seek_value = trim($seek_parts[1]);
145 $q->leftJoin($dbo->qn('#__vikbooking_customers_orders', 'co') . ' ON ' . $dbo->qn('co.idorder') . ' = ' . $dbo->qn('o.id'));
146 $q->leftJoin($dbo->qn('#__vikbooking_customers', 'c') . ' ON ' . $dbo->qn('c.id') . ' = ' . $dbo->qn('co.idcustomer'));
147 $q->where('CONCAT_WS(\' \', ' . $dbo->qn('c.first_name') . ', ' . $dbo->qn('c.last_name') . ') LIKE ' . $dbo->q("%{$seek_value}%"));
148 } else {
149 // seek for various values
150 $q->andWhere([
151 $dbo->qn('o.id') . ' = ' . $dbo->q($pconfirmnumber),
152 $dbo->qn('o.confirmnumber') . ' LIKE ' . $dbo->q("%{$pconfirmnumber}%"),
153 $dbo->qn('o.idorderota') . ' = ' . $dbo->q($pconfirmnumber),
154 ], $glue = 'OR');
155 }
156
157 $q->order($dbo->qn("o.{$orderby}") . ' ' . $ordersort);
158
159 $dbo->setQuery($q, $lim0, $lim);
160 $rows = $dbo->loadAssocList();
161
162 if ($rows) {
163 $dbo->setQuery('SELECT FOUND_ROWS();');
164 $totres = $dbo->loadResult();
165 if ($totres == 1 && count($rows) == 1) {
166 $app->redirect("index.php?option=com_vikbooking&task=editorder&cid[]=".$rows[0]['id']);
167 $app->close();
168 }
169
170 $ordersfound = true;
171 jimport('joomla.html.pagination');
172 $pageNav = new JPagination( $totres, $lim0, $lim );
173 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
174 }
175 }
176
177 if (!$ordersfound) {
178 if (!empty($pcust_id)) {
179 $q = "SELECT SQL_CALC_FOUND_ROWS `o`.*,`co`.`idcustomer`,CONCAT_WS(' ', `c`.`first_name`, `c`.`last_name`) AS `customer_fullname` FROM `#__vikbooking_orders` AS `o` LEFT JOIN `#__vikbooking_customers_orders` `co` ON `co`.`idorder`=`o`.`id` LEFT JOIN `#__vikbooking_customers` `c` ON `c`.`id`=`co`.`idcustomer` AND `c`.`id`=".$pcust_id." WHERE ".(!empty($dates_filter) ? $dates_filter.' AND ' : '').(!empty($payment_filter) ? $payment_filter.' AND ' : '').(!empty($status_filter) ? $status_filter.' AND ' : '')."`co`.`idcustomer`=".$pcust_id." ORDER BY `o`.`".$orderby."` ".$ordersort;
180 } elseif (!empty($pidroom) || !empty($pcategory_id)) {
181 // ONLY_FULL_GROUP_BY safe
182 $clauses = array();
183 if (!empty($dates_filter)) {
184 array_push($clauses, $dates_filter);
185 }
186 if (!empty($payment_filter)) {
187 array_push($clauses, $payment_filter);
188 }
189 if (!empty($status_filter)) {
190 array_push($clauses, $status_filter);
191 }
192 if (!empty($pidroom)) {
193 array_push($clauses, '`or`.`idroom`=' . $pidroom);
194 }
195 if (!empty($pcategory_id)) {
196 array_push($clauses, "(`r`.`idcat`='" . $pcategory_id . ";' OR `r`.`idcat` LIKE '" . $pcategory_id . ";%' OR `r`.`idcat` LIKE '%;" . $pcategory_id . ";%' OR `r`.`idcat` LIKE '%;" . $pcategory_id . ";')");
197 }
198 if (strlen($pchannel)) {
199 array_push($clauses, '`o`.`channel` ' . ($pchannel == '-1' ? 'IS NULL' : "LIKE " . $dbo->quote("%" . $pchannel . "%")));
200 }
201 $q = "SELECT SQL_CALC_FOUND_ROWS DISTINCT `o`.*,`or`.`idorder`,`r`.`idcat` FROM `#__vikbooking_orders` AS `o` LEFT JOIN `#__vikbooking_ordersrooms` AS `or` ON `o`.`id`=`or`.`idorder` LEFT JOIN `#__vikbooking_rooms` AS `r` ON `or`.`idroom`=`r`.`id` WHERE " . implode(' AND ', $clauses) . " ORDER BY `o`.`".$orderby."` ".$ordersort;
202 } else {
203 $clauses = array();
204 if (!empty($dates_filter)) {
205 $clauses[] = $dates_filter;
206 }
207 if (!empty($payment_filter)) {
208 $clauses[] = $payment_filter;
209 }
210 if (!empty($status_filter)) {
211 $clauses[] = $status_filter;
212 }
213 if (strlen($pchannel)) {
214 $clauses[] = "`o`.`channel` ".($pchannel == '-1' ? 'IS NULL' : "LIKE ".$dbo->quote("%".$pchannel."%"));
215 }
216 $q = "SELECT SQL_CALC_FOUND_ROWS `o`.* FROM `#__vikbooking_orders` AS `o`".(count($clauses) > 0 ? " WHERE ".implode(' AND ', $clauses) : "")." ORDER BY `o`.`".$orderby."` ".$ordersort.($orderby == 'ts' && $ordersort == 'DESC' ? ', `o`.`id` DESC' : '');
217 }
218 $dbo->setQuery($q, $lim0, $lim);
219 $dbo->execute();
220
221 /**
222 * Call assertListQuery() from the View class to make sure the filters set
223 * do not produce an empty result. This would reset the page in this case.
224 *
225 * @since 1.12.0 (J) - 1.2.0 (WP)
226 */
227 $this->assertListQuery($lim0, $lim);
228 //
229
230 if ($dbo->getNumRows()) {
231 $rows = $dbo->loadAssocList();
232 $dbo->setQuery('SELECT FOUND_ROWS();');
233 jimport('joomla.html.pagination');
234 $pageNav = new JPagination( $dbo->loadResult(), $lim0, $lim );
235 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
236 }
237 }
238
239 /**
240 * Filter by category
241 *
242 * @since 1.13
243 */
244 $categories = array();
245 $q = "SELECT `id`,`name` FROM `#__vikbooking_categories` ORDER BY `name` ASC;";
246 $dbo->setQuery($q);
247 $dbo->execute();
248 if ($dbo->getNumRows() > 0) {
249 $allcats = $dbo->loadAssocList();
250 foreach ($allcats as $cat) {
251 $categories[$cat['id']] = $cat['name'];
252 }
253 }
254 //
255
256 $this->rows = $rows;
257 $this->allrooms = $allrooms;
258 $this->lim0 = $lim0;
259 $this->navbut = $navbut;
260 $this->orderby = $orderby;
261 $this->ordersort = $ordersort;
262 $this->categories = $categories;
263
264 // Display the template
265 parent::display($tpl);
266 }
267
268 /**
269 * Sets the toolbar
270 */
271 protected function addToolBar() {
272 JToolBarHelper::title(JText::translate('VBMAINORDERTITLE'), 'vikbooking');
273 if (JFactory::getUser()->authorise('core.create', 'com_vikbooking')) {
274 JToolBarHelper::addNew('calendar', JText::translate('VBO_NEW_BOOKING'));
275 JToolBarHelper::spacer();
276 }
277 if (JFactory::getUser()->authorise('core.edit', 'com_vikbooking')) {
278 JToolBarHelper::editList('editorder', JText::translate('VBMAINORDEREDIT'));
279 JToolBarHelper::spacer();
280 }
281 if (JFactory::getUser()->authorise('core.vbo.management', 'com_vikbooking')) {
282 JToolBarHelper::custom( 'orders', 'file-2', 'file-2', JText::translate('VBOGENINVOICES'), true);
283 JToolBarHelper::spacer();
284 }
285 if (JFactory::getUser()->authorise('core.delete', 'com_vikbooking')) {
286 JToolBarHelper::deleteList(JText::translate('VBDELCONFIRM'), 'removeorders', JText::translate('VBMAINORDERDEL'));
287 JToolBarHelper::spacer();
288 JToolBarHelper::spacer();
289 }
290 }
291
292 }
293