PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
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 trunk, at admin/views/orders/view.html.php

295 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 } elseif ($pstatus == 'quote') {
87 $status_filter = "`o`.`idquote` IS NOT NULL";
88 }
89 }
90 $pidpayment = $app->getUserStateFromRequest("vbo.orders.idpayment", 'idpayment', 0, 'int');
91 $payment_filter = '';
92 if (!empty($pidpayment)) {
93 $payment_filter = "`o`.`idpayment` LIKE '".$pidpayment."=%'";
94 }
95 $ordersfound = false;
96 $lim = $app->getUserStateFromRequest("com_vikbooking.limit", 'limit', $app->get('list_limit'), 'int');
97 $lim0 = $app->getUserStateFromRequest("vbo.orders.limitstart", 'limitstart', 0, 'int');
98 $session = JFactory::getSession();
99 $pvborderby = VikRequest::getString('vborderby', '', 'request');
100 $pvbordersort = VikRequest::getString('vbordersort', '', 'request');
101 $validorderby = array('id', 'ts', 'days', 'checkin', 'checkout', 'total');
102 $orderby = $session->get('vbViewOrdersOrderby', 'ts');
103 $ordersort = $session->get('vbViewOrdersOrdersort', 'DESC');
104 if (!empty($pvborderby) && in_array($pvborderby, $validorderby)) {
105 $orderby = $pvborderby;
106 $session->set('vbViewOrdersOrderby', $orderby);
107 if (!empty($pvbordersort) && in_array($pvbordersort, array('ASC', 'DESC'))) {
108 $ordersort = $pvbordersort;
109 $session->set('vbViewOrdersOrdersort', $ordersort);
110 }
111 }
112
113 $q = "SELECT `id`,`name` FROM `#__vikbooking_rooms` ORDER BY `name` ASC;";
114 $dbo->setQuery($q);
115 $allrooms = $dbo->loadAssocList();
116
117 if (!empty($pconfirmnumber)) {
118 /**
119 * We allow looking for a specific ID, OTAID, Coupon code etc.. by using syntaxes like "id: 500"
120 */
121 $q = $dbo->getQuery(true)->select('SQL_CALC_FOUND_ROWS `o`.*');
122 $q->from($dbo->qn('#__vikbooking_orders', 'o'));
123 $q->where(1);
124
125 if (stripos($pconfirmnumber, 'id:') === 0) {
126 // search by ID or OTA ID
127 $seek_parts = explode('id:', $pconfirmnumber);
128 $seek_value = trim($seek_parts[1]);
129 $q->andWhere([
130 $dbo->qn('o.id') . ' = ' . $dbo->q($seek_value),
131 $dbo->qn('o.idorderota') . ' = ' . $dbo->q($seek_value),
132 ], $glue = 'OR');
133 } elseif (stripos($pconfirmnumber, 'otaid:') === 0) {
134 // search by OTA Booking ID
135 $seek_parts = explode('otaid:', $pconfirmnumber);
136 $seek_value = trim($seek_parts[1]);
137 $q->where($dbo->qn('o.idorderota') . ' = ' . $dbo->q($seek_value));
138 } elseif (stripos($pconfirmnumber, 'coupon:') === 0) {
139 // search by coupon code
140 $seek_parts = explode('coupon:', $pconfirmnumber);
141 $seek_value = trim($seek_parts[1]);
142 $q->where($dbo->qn('o.coupon') . ' LIKE ' . $dbo->q("%{$seek_value}%"));
143 } elseif (stripos($pconfirmnumber, 'name:') === 0) {
144 // search by customer nominative
145 $seek_parts = explode('name:', $pconfirmnumber);
146 $seek_value = trim($seek_parts[1]);
147 $q->leftJoin($dbo->qn('#__vikbooking_customers_orders', 'co') . ' ON ' . $dbo->qn('co.idorder') . ' = ' . $dbo->qn('o.id'));
148 $q->leftJoin($dbo->qn('#__vikbooking_customers', 'c') . ' ON ' . $dbo->qn('c.id') . ' = ' . $dbo->qn('co.idcustomer'));
149 $q->where('CONCAT_WS(\' \', ' . $dbo->qn('c.first_name') . ', ' . $dbo->qn('c.last_name') . ') LIKE ' . $dbo->q("%{$seek_value}%"));
150 } else {
151 // seek for various values
152 $q->andWhere([
153 $dbo->qn('o.id') . ' = ' . $dbo->q($pconfirmnumber),
154 $dbo->qn('o.confirmnumber') . ' LIKE ' . $dbo->q("%{$pconfirmnumber}%"),
155 $dbo->qn('o.idorderota') . ' = ' . $dbo->q($pconfirmnumber),
156 ], $glue = 'OR');
157 }
158
159 $q->order($dbo->qn("o.{$orderby}") . ' ' . $ordersort);
160
161 $dbo->setQuery($q, $lim0, $lim);
162 $rows = $dbo->loadAssocList();
163
164 if ($rows) {
165 $dbo->setQuery('SELECT FOUND_ROWS();');
166 $totres = $dbo->loadResult();
167 if ($totres == 1 && count($rows) == 1) {
168 $app->redirect("index.php?option=com_vikbooking&task=editorder&cid[]=".$rows[0]['id']);
169 $app->close();
170 }
171
172 $ordersfound = true;
173 jimport('joomla.html.pagination');
174 $pageNav = new JPagination( $totres, $lim0, $lim );
175 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
176 }
177 }
178
179 if (!$ordersfound) {
180 if (!empty($pcust_id)) {
181 $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;
182 } elseif (!empty($pidroom) || !empty($pcategory_id)) {
183 // ONLY_FULL_GROUP_BY safe
184 $clauses = array();
185 if (!empty($dates_filter)) {
186 array_push($clauses, $dates_filter);
187 }
188 if (!empty($payment_filter)) {
189 array_push($clauses, $payment_filter);
190 }
191 if (!empty($status_filter)) {
192 array_push($clauses, $status_filter);
193 }
194 if (!empty($pidroom)) {
195 array_push($clauses, '`or`.`idroom`=' . $pidroom);
196 }
197 if (!empty($pcategory_id)) {
198 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 . ";')");
199 }
200 if (strlen($pchannel)) {
201 array_push($clauses, '`o`.`channel` ' . ($pchannel == '-1' ? 'IS NULL' : "LIKE " . $dbo->quote("%" . $pchannel . "%")));
202 }
203 $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;
204 } else {
205 $clauses = array();
206 if (!empty($dates_filter)) {
207 $clauses[] = $dates_filter;
208 }
209 if (!empty($payment_filter)) {
210 $clauses[] = $payment_filter;
211 }
212 if (!empty($status_filter)) {
213 $clauses[] = $status_filter;
214 }
215 if (strlen($pchannel)) {
216 $clauses[] = "`o`.`channel` ".($pchannel == '-1' ? 'IS NULL' : "LIKE ".$dbo->quote("%".$pchannel."%"));
217 }
218 $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' : '');
219 }
220 $dbo->setQuery($q, $lim0, $lim);
221 $dbo->execute();
222
223 /**
224 * Call assertListQuery() from the View class to make sure the filters set
225 * do not produce an empty result. This would reset the page in this case.
226 *
227 * @since 1.12.0 (J) - 1.2.0 (WP)
228 */
229 $this->assertListQuery($lim0, $lim);
230 //
231
232 if ($dbo->getNumRows()) {
233 $rows = $dbo->loadAssocList();
234 $dbo->setQuery('SELECT FOUND_ROWS();');
235 jimport('joomla.html.pagination');
236 $pageNav = new JPagination( $dbo->loadResult(), $lim0, $lim );
237 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
238 }
239 }
240
241 /**
242 * Filter by category
243 *
244 * @since 1.13
245 */
246 $categories = array();
247 $q = "SELECT `id`,`name` FROM `#__vikbooking_categories` ORDER BY `name` ASC;";
248 $dbo->setQuery($q);
249 $dbo->execute();
250 if ($dbo->getNumRows() > 0) {
251 $allcats = $dbo->loadAssocList();
252 foreach ($allcats as $cat) {
253 $categories[$cat['id']] = $cat['name'];
254 }
255 }
256 //
257
258 $this->rows = $rows;
259 $this->allrooms = $allrooms;
260 $this->lim0 = $lim0;
261 $this->navbut = $navbut;
262 $this->orderby = $orderby;
263 $this->ordersort = $ordersort;
264 $this->categories = $categories;
265
266 // Display the template
267 parent::display($tpl);
268 }
269
270 /**
271 * Sets the toolbar
272 */
273 protected function addToolBar() {
274 JToolBarHelper::title(JText::translate('VBMAINORDERTITLE'), 'vikbooking');
275 if (JFactory::getUser()->authorise('core.create', 'com_vikbooking')) {
276 JToolBarHelper::addNew('calendar', JText::translate('VBO_NEW_BOOKING'));
277 JToolBarHelper::spacer();
278 }
279 if (JFactory::getUser()->authorise('core.edit', 'com_vikbooking')) {
280 JToolBarHelper::editList('editorder', JText::translate('VBMAINORDEREDIT'));
281 JToolBarHelper::spacer();
282 }
283 if (JFactory::getUser()->authorise('core.vbo.management', 'com_vikbooking')) {
284 JToolBarHelper::custom( 'orders', 'file-2', 'file-2', JText::translate('VBOGENINVOICES'), true);
285 JToolBarHelper::spacer();
286 }
287 if (JFactory::getUser()->authorise('core.delete', 'com_vikbooking')) {
288 JToolBarHelper::deleteList(JText::translate('VBDELCONFIRM'), 'removeorders', JText::translate('VBMAINORDERDEL'));
289 JToolBarHelper::spacer();
290 JToolBarHelper::spacer();
291 }
292 }
293
294 }
295