PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.7
VikBooking Hotel Booking Engine & PMS v1.6.7
1.8.16 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 All 37 releases
vikbooking / admin / views / orders / view.html.php

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

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