Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.01 KB | None | 0 0
  1. <?php
  2.  
  3. function hk_reservations_fetch() {
  4. $type = variable_get('hkeeper_pms_integration');
  5. $data = [];
  6. if ($type == 'mews') {
  7. $data = hk_mews_get_reservations();
  8. }
  9. if ($type == 'apaleo') {
  10. $data = hk_apaleo_get_reservations();
  11. }
  12. if ($type == 'clock') {
  13.  
  14. $ch = curl_init();
  15.  
  16. curl_setopt($ch, CURLOPT_URL, variable_get('hk_clock_url') . '/rooms');
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  18. curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  20. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  21. curl_setopt($ch, CURLOPT_USERPWD, variable_get('hk_clock_username') . ":" . variable_get('hk_clock_key'));
  22. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  23. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  24. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  25. $response = curl_exec($ch);
  26. $res_rooms = drupal_json_decode($response);
  27. $statuses = _hk_clock_get_rooms_statuses();
  28. $res_cat = _hk_clock_get_rooms_categories();
  29.  
  30. // construct rooms categories
  31. $categories = [];
  32. $rooms_hsk = [];
  33. foreach ($res_cat as $k => $v) {
  34. $categories[$v['id']] = $v;
  35. }
  36.  
  37. $st_configs = [];
  38. foreach ($statuses as $k => $v) {
  39. foreach ($v['rooms'] as $roomkey => $room) {
  40. $st_configs[$room['id']]['housekeeping_status'] = (is_null($room['housekeeping_status'])) ? 'Clean' : $room['housekeeping_status'];
  41. }
  42. }
  43.  
  44. // reassign a category for each room
  45. foreach ($res_rooms as $k => $v) {
  46. $v['category'] = isset($v['room_type_id']) ? $categories[$v['room_type_id']] : '';
  47. $v['housekeeping_status'] = $st_configs[$v['id']]['housekeeping_status'];
  48. // dsm($v['id']);
  49. // dsm($v);
  50. $rooms_hsk[$v['id']] = $v['housekeeping_status'];
  51. }
  52.  
  53. $available = $clean = [];
  54. foreach ($statuses as $ss) {
  55. foreach ($ss['rooms'] as $r) {
  56. $available[$r['id']] = $r['available'];
  57. $clean[$r['id']] = $r['housekeeping_status'] == 'checked_out' ? 0 : 1;
  58. }
  59. }
  60.  
  61. // exclude checkout/dirty rooms with last update in today
  62. $rooms_exclude = db_select('eck_hk_room', 'r')
  63. ->fields('r', ['id'])
  64. ->condition('r.room_occupancy', variable_get('hk_pms_occupancy_relationship_checked_out', 136))
  65. ->condition('r.room_availability', 29)
  66. ->condition('r.changed', strtotime('today'), '>=')
  67. ->execute()
  68. ->fetchCol();
  69.  
  70.  
  71. // make available old checked out/ dirty rooms
  72. $rooms = db_select('eck_hk_room', 'r')
  73. ->fields('r', ['id'])
  74. ->condition('r.room_occupancy', variable_get('hk_pms_occupancy_relationship_checked_out', 136))
  75. ->condition('r.changed', strtotime('today'), '<=')
  76. ->execute()
  77. ->fetchCol();
  78.  
  79. foreach($rooms as $r){
  80. $room = entity_load_single('hk_room', $r);
  81. $room->room_occupancy = variable_get('hk_pms_occupancy_relationship_available', 66);
  82. $room->rsv_hskp = 0;
  83. entity_save('hk_room', $room);
  84. }
  85.  
  86. $query = db_select('eck_hk_room', 'r');
  87.  
  88. // remove all previously selected rooms (checked out and dirty)
  89. if ($rooms_exclude) {
  90. $query->condition('r.id', $rooms_exclude, 'NOT IN');
  91. }
  92.  
  93. $query->fields('r', ['id', 'title', 'pms']);
  94. $rooms = $query->execute()->fetchAll();
  95.  
  96. // create an array of rooms for check
  97. foreach ($rooms as $r) {
  98. $room_ids[] = $r->id;
  99. }
  100.  
  101. // get all reservations which checkout day is today
  102. $reservations = db_select('eck_hk_reservation', 'r')
  103. ->fields('r', ['room', 'code'])
  104. ->condition('r.room', $room_ids)
  105. ->condition('r.date_checkout', strtotime('today'))
  106. ->execute()
  107. ->fetchAllKeyed();
  108.  
  109. $today = date('Y-m-d');
  110.  
  111. // remove false if want to work with cached data
  112. if (FALSE && $cache = cache_get('hk_clock_get_reservations2')) {
  113. $data = $cache->data;
  114. }
  115. else {
  116. foreach ($rooms as $room) {
  117. // $continue = FALSE;
  118. $r = entity_load_single('hk_room', $room->id);
  119.  
  120. // check if rooms is available
  121. if ($available[$room->pms]) {
  122. $r->room_occupancy = variable_get('hk_pms_occupancy_relationship_available', 66);
  123. // $continue = TRUE;
  124. }
  125.  
  126. // $r->room_availability = $clean[$room->pms] ? 28 : 29;
  127. // $r->rsv_hskp = '';
  128. //
  129. // entity_save('hk_room', $r);
  130. //
  131. // if ($continue) {
  132. // continue;
  133. // }
  134.  
  135. // get room reservation
  136. $ch = curl_init();
  137. curl_setopt($ch, CURLOPT_URL, variable_get('hk_clock_url') . '/rooms/' . $room->pms . '/' . $today . '/bookings?show_departures');
  138. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  139. curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  140. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  141. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  142. curl_setopt($ch, CURLOPT_USERPWD, variable_get('hk_clock_username') . ":" . variable_get('hk_clock_key'));
  143. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  144. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  145. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  146.  
  147. $response = curl_exec($ch);
  148. $result = drupal_json_decode($response);
  149.  
  150. if ($result) {
  151. $item = hk_clock_get_reservation($result[0]['id']);
  152.  
  153. if ($item['booking_status'] == 'expected' && isset($reservations[$room->id])) {
  154. $item['booking_status'] = 'due_out_expected';
  155.  
  156. $current_reservation = hk_clock_get_reservation($reservations[$room->id]);
  157.  
  158. if ($current_reservation['booking_status'] == 'checked_out') {
  159. $item['booking_status'] = 'checked_out_expected';
  160. }
  161. }
  162. $data[] = $item;
  163. }
  164. curl_close($ch);
  165. // sleep(0.1);
  166. }
  167. cache_set('hk_clock_get_reservations2', $data);
  168. }
  169.  
  170. // get all housekeeping type statuses
  171.  
  172. $configs = db_select('eck_hk_config', 'c')
  173. ->fields('c', ['pms', 'id'])
  174. ->condition('c.type', 'reservation_housekeeping')
  175. ->isNotNull('c.pms')
  176. ->execute()->fetchAllKeyed();
  177.  
  178. // apply housekeeping statuses
  179. foreach ($data as $k => $v) {
  180. if (isset($v['pms_rate']) && $v['pms_rate'] && !$available[$v['room']]) {
  181. $pms_rate = mb_strtolower($v['pms_rate']['name']);
  182. foreach ($configs as $type => $id) {
  183. if (strpos($pms_rate, $type)) {
  184. $data[$k]['pms_rate_code'] = $id;
  185. }
  186. }
  187. }
  188. }
  189.  
  190. // process all rooms not checkedout/dirty
  191. if ($rooms) {
  192.  
  193. $query = db_select('eck_hk_room', 'r')->fields('r', ['id']);
  194.  
  195. if ($status = variable_get('hk_reservation_prevent_set_room_available')) {
  196. $query->leftJoin('eck_hk_config', 'c', 'r.room_occupancy = c.id');
  197. $query->condition('c.uuid', [$status], 'NOT IN');
  198. }
  199.  
  200. $query->fields('r', ['id']);
  201. $query->condition('r.pms', array_filter($room_ids), 'NOT IN');
  202. $query->condition('c.id', '', '!=');
  203. $ids = $query->execute()->fetchCol();
  204.  
  205. if ($ids) {
  206. $rooms = entity_load('hk_room', $ids);
  207. foreach ($rooms as $r) {
  208. //if there are a reservation for this room which one finish today
  209. if (isset($reservations[$r->id])) {
  210.  
  211. // set this room occupancy to departure
  212. $r->room_occupancy = variable_get('hk_pms_occupancy_relationship_due_out', 137);
  213.  
  214. // get old reservation for this room if any
  215. $current_reservation = hk_clock_get_reservation($reservations[$r->id]);
  216.  
  217. // check old reservation for this room
  218. if ($current_reservation['booking_status'] == 'checked_out') {
  219. // set room occupancy to checked out
  220. $r->room_occupancy = variable_get('hk_pms_occupancy_relationship_checked_out', 136);
  221. }
  222. }
  223. else {
  224. // make this room available
  225. $r->room_occupancy = variable_get('hk_pms_occupancy_relationship_available', 66);
  226. $r->rsv_hskp = 0;
  227. }
  228.  
  229. // save the room
  230. entity_save('hk_room', $r);
  231. }
  232. }
  233. }
  234. }
  235. //
  236. // foreach ($data as $d) {
  237. // $r = db_select('eck_hk_room', 'r')
  238. // ->fields('r', ['title'])
  239. // ->condition('r.pms', $d['room'])
  240. // ->execute()
  241. // ->fetchField();
  242. // dsm($r . ' (' . format_date($d['from'], 'short') . ' - ' . format_date($d['to'], 'short'));
  243. // dsm($d);
  244. // }
  245.  
  246. foreach ($data as $v) {
  247. hk_reservation_preprocess($v);
  248. }
  249. }
  250.  
  251. function hk_reservation_preprocess($data) {
  252.  
  253. $today = strtotime('today');
  254.  
  255. if (!$data['room'] || !$data['id']) {
  256. return;
  257. }
  258.  
  259. // check and remove reservation if it's has been canceled or no_show
  260. if (in_array($data['booking_status'], ['canceled', 'no_show'])) {
  261. $reservation_id = db_select('eck_hk_reservation', 'r')
  262. ->fields('r', ['id'])
  263. ->condition('r.code', $data['id'])
  264. ->execute()
  265. ->fetchField();
  266.  
  267. if ($reservation_id) {
  268. entity_delete('hk_reservation', $reservation_id);
  269. return;
  270. }
  271. }
  272.  
  273.  
  274. // get the room
  275. $room = $data['room'];
  276. $query = db_select('eck_hk_room', 'r')->fields('r', ['id']);
  277. $query->fields('r', ['id']);
  278. $db_or = db_or();
  279. $db_or->condition('r.title', $room);
  280. $db_or->condition('r.pms', $room);
  281. $query->condition($db_or);
  282.  
  283. $room = $query->execute()->fetchField();
  284.  
  285. if ($room) {
  286. if ($data['id']) {
  287.  
  288. // check if reservation already exists
  289. $reservation_id = db_select('eck_hk_reservation', 'r')
  290. ->fields('r', ['id'])
  291. ->condition('r.code', $data['id'])
  292. ->execute()
  293. ->fetchField();
  294.  
  295. // load
  296. if ($reservation_id) {
  297. $r = entity_load_single('hk_reservation', $reservation_id);
  298. $r->is_new = FALSE;
  299. $r->is_new_revision = TRUE;
  300. $r->default_revision = TRUE;
  301. }
  302. // or create
  303. else {
  304. $r = entity_create('hk_reservation', ['type' => 'hk_reservation']);
  305. $r->code = $data['id'];
  306. }
  307.  
  308. // set parameters
  309. $r->date_checkin = $data['from'];
  310. $r->date_checkout = $data['to'];
  311. $r->guest = $data['name'];
  312.  
  313. $room_entity = entity_load_single('hk_room', $room);
  314. $room_update = FALSE;
  315.  
  316. // get room occupancy from reservation booking status
  317. $occupancy = db_query("SELECT id FROM {eck_hk_config} WHERE pms = :pms AND type = 'occupancy_status'", [':pms' => $data['booking_status']])->fetchField();
  318. if ($occupancy) {
  319. $room_entity->room_occupancy = $occupancy;
  320. $room_update = TRUE;
  321. };
  322.  
  323. if ($data['booking_status'] == 'checked_in' && $data['from'] != $today) {
  324. $occupancy = db_query("SELECT id FROM {eck_hk_config} WHERE pms = :pms AND type = 'occupancy_status'", [':pms' => 'stayover'])->fetchField();
  325. if ($occupancy) {
  326. $room_entity->room_occupancy = $occupancy;
  327. }
  328. }
  329.  
  330. if ($data['booking_status'] == 'checked_in' && $data['to'] == $today) {
  331. $occupancy = db_query("SELECT id FROM {eck_hk_config} WHERE pms = :pms AND type = 'occupancy_status'", [':pms' => 'due_out'])->fetchField();
  332. if ($occupancy) {
  333. $room_entity->room_occupancy = $occupancy;
  334. }
  335. }
  336.  
  337. if (variable_get('hk_reservation_room_change') && $data['room'] != $room) {
  338. if (variable_get('hk_reservation_room_change_availability') || variable_get('hk_reservation_room_change_occupancy')) {
  339. if (variable_get('hk_reservation_room_change_availability')) {
  340. $availability = entity_uuid_load_single('hk_config', variable_get('hk_reservation_room_change_availability'));
  341. $room_entity->room_availability = $availability->id;
  342. $room_update = TRUE;
  343. }
  344. if (variable_get('hk_reservation_room_change_occupancy')) {
  345. $occupancy = entity_uuid_load_single('hk_config', variable_get('hk_reservation_room_change_occupancy'));
  346. $room_entity->room_occupancy = $occupancy->id;
  347. $room_update = TRUE;
  348. }
  349. }
  350. }
  351.  
  352. if (variable_get('hk_reservation_daily_use') && isset($data['pms_rate']['day']) && $data['pms_rate']['day']) {
  353. if ($day_use_status = variable_get('hk_pms_occupancy_relationship_day_use')) {
  354. $room_entity->room_occupancy = $day_use_status;
  355. }
  356. else {
  357. $day_use_status = variable_get('hk_reservation_daily_use');
  358. $room_entity->room_occupancy = entity_uuid_load_single('hk_config', $day_use_status)->id;
  359. }
  360. $room_update = TRUE;
  361. }
  362.  
  363. if (isset($data['pms_rate_code']) && is_numeric($data['pms_rate_code']) && $data['pms_rate_code']) {
  364. $room_entity->rsv_hskp = $data['pms_rate_code'];
  365. $room_update = TRUE;
  366. }
  367.  
  368. if ($room_update) {
  369. entity_save('hk_room', $room_entity);
  370. }
  371.  
  372. $r->room = $room;
  373. $r->status = 1;
  374. $r->origin = $data['origin'];
  375. $r->pms_note = $data['pms_note'];
  376. $r->pms_rate = isset($data['pms_rate']) && isset($data['pms_rate']['name']) ? $data['pms_rate']['name'] : '';
  377.  
  378. entity_save('hk_reservation', $r);
  379. }
  380. }
  381. }
  382.  
  383. function hk_reservation_process() {
  384.  
  385. $now = time();
  386. $reservations = db_select('eck_hk_reservation', 'r')
  387. ->fields('r', ['date_checkin', 'date_checkout', 'room', 'status'])
  388. // ->condition('r.status', 1)
  389. ->condition('r.date_checkin', $now, '<=')
  390. ->condition('r.date_checkout', $now, '>=')
  391. ->execute()
  392. ->fetchAll();
  393.  
  394.  
  395. $days = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  396. $vars = [];
  397.  
  398. $da_calc = variable_get('hk_reservation_departure_arrival_calc');
  399. $daily_use_calc = variable_get('hk_reservation_daily_use_calc');
  400.  
  401. $da_calc_status = variable_get('hk_reservation_departure_arrival_calc_status');
  402. $daily_use_calc_status = variable_get('hk_reservation_daily_use_calc_status');
  403.  
  404. foreach ($days as $k => $v) {
  405. if (variable_get('reservation_assignment_status_' . $k)) {
  406. $vars[] = [
  407. 'day' => variable_get('reservation_assignment_day_' . $k),
  408. 'time_from' => variable_get('reservation_assignment_from_' . $k),
  409. 'time_to' => variable_get('reservation_assignment_to_' . $k),
  410. 'occupancy_status' => variable_get('reservation_assignment_occupancy_status_' . $k),
  411. 'comment' => variable_get('reservation_assignment_comment_' . $k),
  412. ];
  413. }
  414. }
  415.  
  416. $today = date('z') + 1;
  417. foreach ($reservations as &$r) {
  418. $from = $r->date_checkin;
  419. $to = $r->date_checkout;
  420. $datetime1 = new DateTime("@$to");
  421. $datetime2 = new DateTime("@$from");
  422. $interval = $datetime1->diff($datetime2);
  423. $r->duration = $interval->format('%d');
  424. $r->date_checking_day = date('z', $from) + 1;
  425. $r->date_checkout_day = date('z', $to) + 1;
  426. $r->action = hk_reservation_action($r, $vars, $today);
  427. }
  428.  
  429. if ($da_calc || $daily_use_calc) {
  430. $today = format_date(time(), 'custom', 'd.m.Y');
  431. $query = db_select('eck_hk_reservation', 'r')->fields('r', ['id', 'room']);
  432. $query->addExpression("from_unixtime(date_checkin, '%d%.%m.%Y')", 'c_date_checkin');
  433. $query->addExpression("from_unixtime(date_checkout, '%d%.%m.%Y')", 'c_date_checkout');
  434. $query->where("FROM_UNIXTIME(date_checkin, '%d%.%m.%Y') = :date OR FROM_UNIXTIME(date_checkout, '%d%.%m.%Y') = :date", [':date' => $today]);
  435.  
  436. $reservations = $query->execute()->fetchAll();
  437.  
  438. foreach ($reservations as $r) {
  439. $res[$r->room][$r->id] = $r;
  440. }
  441.  
  442. foreach ($res as $k => $r) {
  443. if (count($r) == 1) {
  444. unset($res[$k]);
  445. }
  446. else {
  447. $res[$k] = array_values($res[$k]);
  448. }
  449. }
  450.  
  451. foreach ($res as $room_id => $v) {
  452. $room = entity_load_single('hk_room', $room_id);
  453.  
  454. if ($daily_use_calc && $v[1]->c_date_checkout == $today) {
  455. $room->room_occupancy = $da_calc_status;
  456. }
  457. else {
  458. $room->room_occupancy = $daily_use_calc_status;
  459. }
  460. entity_save('hk_room', $room);
  461. }
  462. }
  463. }
  464.  
  465.  
  466. function hk_reservation_action($r, $vars, $today) {
  467. $type = FALSE;
  468. $current_time_minutes = round((time() - strtotime("today")) / 60);
  469.  
  470. // dsm('-' . $today . '---' . $r->date_checking_day);
  471. // first
  472. if ($today == $r->date_checking_day) {
  473. $type = 'first';
  474. }
  475. // second
  476. elseif (($today - 1) == $r->date_checking_day) {
  477. $type = 'second';
  478. }
  479. // last
  480. elseif ($today == $r->date_checkout_day) {
  481. $type = 'last';
  482. }
  483. // penultimate
  484. elseif ($today == $r->date_checkout_day) {
  485. $type = 'penultimate';
  486. }
  487. else {
  488. // calculate odds and evens days
  489. $days = range($r->date_checking_day, $r->date_checkout_day);
  490. foreach ($days as $k => $v) {
  491. if ($k % 2) {
  492. $ods[] = $v;
  493. $type = 'odd';
  494. }
  495. else {
  496. $even[] = $v;
  497. $type = 'even';
  498. }
  499. }
  500. }
  501. if ($type) {
  502. foreach ($vars as $v) {
  503. if ($v['day'] == $type && $v['occupancy_status']) {
  504. $start = $v['time_from'] ? _hk_reservation_calculate_minutes($v['time_from']) : 0;
  505. $end = $v['time_from'] ? _hk_reservation_calculate_minutes($v['time_to']) : 1440;
  506. if ($current_time_minutes >= $start && $current_time_minutes <= $end) {
  507. if ($r->room) {
  508. $room = entity_load_single('hk_room', $r->room);
  509. $occupancy_status = entity_uuid_load_single('hk_config', $v['occupancy_status']);
  510. if ($room->room_occupancy != $occupancy_status) {
  511. $room->room_occupancy = $occupancy_status->id;
  512. entity_save('hk_room', $room);
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. }
  520.  
  521. //$data = hkeeper_ezee_query();
  522. //foreach ($data['guests'] as $g) {
  523. // $g = array_shift($g);
  524. // $i = [];
  525. // $i['id'] = $g->reservationno;
  526. // $i['room'] = $g->room;
  527. // $i['name'] = $g->guestname;
  528. // $i['from'] = strtotime($g->checkindate);
  529. // $i['to'] = strtotime($g->checkoutdate);
  530. // $i['origin'] = 'ezee';
  531. // hk_reservation_insert($i);
  532. //}
  533.  
  534. //$ids = db_select('eck_hk_reservation', 'r')->fields('r', ['id'])->execute()->fetchCol();
  535. //foreach($ids as $id){
  536. // entity_delete('hk_reservation', $id);
  537. //}
  538.  
  539.  
  540. function _hk_reservation_calculate_minutes($time) {
  541. $time = explode(':', $time);
  542. return ($time[0] * 60) + ($time[1]);
  543. }
  544.  
  545.  
  546. function _hk_reservation_revision_diff($entity, $v) {
  547.  
  548. $revision = [];
  549.  
  550. if (isset($entity->is_new)) {
  551. return;
  552. }
  553.  
  554. if (isset($v['employee']) && $v['employee']) {
  555. $v['employee'] = entity_uuid_load_single('user', $v['employee'])->uid;
  556. }
  557. if (isset($v['employee']) && $entity->employee != $v['employee']) {
  558. $employee_original = $entity->employee ? user_load($entity->employee)->name : 'None';
  559. $employee_new = $v['employee'] ? user_load($v['employee'])->name : 'None';
  560. $revision['log'][t('Receiver', [], ['context' => 'hkeeper'])] = [
  561. $employee_original,
  562. $employee_new,
  563. ];
  564. }
  565.  
  566. if (isset($v['room']) && $entity->room != $v['room']) {
  567. $room_original = $entity->room ? entity_load_single('hk_room', $entity->room)->title : 'None';
  568. $room_new = $v['room'] ? entity_load_single('hk_room', $v['room'])->title : 'None';
  569. $revision['log'][t('Room', [], ['context' => 'hkeeper'])] = [
  570. $room_original,
  571. $room_new,
  572. ];
  573. }
  574.  
  575. if (isset($v['notes']) && $v['notes']) {
  576. $revision['log'][t('Notes', [], ['context' => 'hkeeper'])] = [
  577. '',
  578. $v['notes'],
  579. ];
  580. }
  581.  
  582. if (isset($revision['log'])) {
  583. global $user;
  584. $revision['uid'] = $user->uid;
  585. return $revision;
  586. }
  587. }
  588.  
  589.  
  590. //$available = $clean = [];
  591. //foreach (_hk_clock_get_rooms_statuses() as $ss) {
  592. // foreach ($ss['rooms'] as $r) {
  593. // $available[$r['id']] = $r['available'];
  594. // $clean[$r['id']] = $r['housekeeping_status'] == 'checked_out' ? 0 : 1;
  595. // }
  596. //}
  597. //$rooms = db_select('eck_hk_room', 'r')
  598. // ->fields('r', ['id', 'title', 'pms'])
  599. // ->execute()
  600. // ->fetchAll();
  601. //
  602. //$today = date('Y-m-d');
  603. //if ($cache = cache_get('hk_clock_get_reservations2')) {
  604. // $data = $cache->data;
  605. //}
  606. //else {
  607. // foreach ($rooms as $room) {
  608. // $continue = FALSE;
  609. // $r = entity_load_single('hk_room', $room->id);
  610. //
  611. // // check if rooms is available
  612. // if ($available[$room->pms]) {
  613. // $r->room_occupancy = 66;
  614. // $continue = TRUE;
  615. // }
  616. //
  617. // $r->room_availability = $clean[$room->pms] ? 28 : 29;
  618. // $r->rsv_hskp = '';
  619. //
  620. // entity_save('hk_room', $r);
  621. //
  622. // if ($continue) {
  623. // continue;
  624. // }
  625. //
  626. // // get room reservation
  627. // $ch = curl_init();
  628. // curl_setopt($ch, CURLOPT_URL, variable_get('hk_clock_url') . '/rooms/' . $room->pms . '/' . $today . '/bookings');
  629. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  630. // curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  631. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  632. // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
  633. // curl_setopt($ch, CURLOPT_USERPWD, variable_get('hk_clock_username') . ":" . variable_get('hk_clock_key'));
  634. // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
  635. // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  636. // curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']);
  637. //
  638. // $response = curl_exec($ch);
  639. // $result = drupal_json_decode($response);
  640. //
  641. // if ($result) {
  642. // $data[] = hk_clock_get_reservation($result[0]['id']);
  643. // }
  644. // curl_close($ch);
  645. // sleep(0.1);
  646. // }
  647. // cache_set('hk_clock_get_reservations2', $data);
  648. //}
  649. //
  650. //// $data = hk_clock_get_reservations();
  651. //$configs = db_select('eck_hk_config', 'c')
  652. // ->fields('c', ['pms', 'id'])
  653. // ->condition('c.type', 'reservation_housekeeping')
  654. // ->isNotNull('c.pms')
  655. // ->execute()->fetchAllKeyed();
  656. //
  657. //foreach ($data as $k => $v) {
  658. // if ($v['room'] == '415019' && $available[$v['room']] == TRUE) {
  659. // // dsm('-' . $v['room'] . '-');
  660. // }
  661. // if (isset($v['pms_rate']) && $v['pms_rate'] && !$available[$v['room']]) {
  662. // $pms_rate = mb_strtolower($v['pms_rate']['name']);
  663. // foreach ($configs as $type => $id) {
  664. // if (strpos($pms_rate, $type)) {
  665. // $data[$k]['pms_rate_code'] = $id;
  666. // }
  667. // }
  668. // }
  669. //}
  670. //
  671. //
  672. //foreach($data as $d){
  673. // $r = db_select('eck_hk_room','r')->fields('r',['title'])->condition('r.pms', $d['room'])->execute()->fetchField();
  674. // dsm($r .' ('. format_date($d['from'],'short').' - '. format_date($d['to'],'short'));
  675. // dsm($d);
  676. //}
  677.  
  678.  
  679. function _hk_custom_hours_range($lower = 0, $upper = 86400, $step = 3600, $format = '') {
  680. $times = [];
  681. $times[''] = t('None');
  682.  
  683. if (empty($format)) {
  684. $format = 'g:i a';
  685. }
  686.  
  687. foreach (range($lower, $upper, $step) as $increment) {
  688. $increment = gmdate('H:i', $increment);
  689.  
  690. [$hour, $minutes] = explode(':', $increment);
  691.  
  692. $date = new DateTime($hour . ':' . $minutes);
  693.  
  694. $times[(string) $increment] = $date->format($format);
  695. }
  696.  
  697. return $times;
  698. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement