| @@ -1,0 +1,70 @@ | ||
| 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 VikBookingViewRefundtn extends JViewVikBooking { | |
| 17 | + | |
| 18 | + function display($tpl = null) { | |
| 19 | + // This view is usually called within a modal box, so it does not require the toolbar or page title | |
| 20 | + | |
| 21 | + $cid = VikRequest::getVar('cid', array(0)); | |
| 22 | + $id = $cid[0]; | |
| 23 | + | |
| 24 | + $dbo = JFactory::getDbo(); | |
| 25 | + $mainframe = JFactory::getApplication(); | |
| 26 | + | |
| 27 | + $q = "SELECT * FROM `#__vikbooking_orders` WHERE `id`=".(int)$id." AND `status`!='standby';"; | |
| 28 | + $dbo->setQuery($q); | |
| 29 | + $dbo->execute(); | |
| 30 | + if ($dbo->getNumRows() < 1) { | |
| 31 | + $mainframe->redirect('index.php?option=com_vikbooking'); | |
| 32 | + exit; | |
| 33 | + } | |
| 34 | + $row = $dbo->loadAssoc(); | |
| 35 | + | |
| 36 | + // get booking history instance | |
| 37 | + $history_obj = VikBooking::getBookingHistoryInstance(); | |
| 38 | + $history_obj->setBid($row['id']); | |
| 39 | + | |
| 40 | + // get payment information | |
| 41 | + $payment = VikBooking::getPayment($row['idpayment']); | |
| 42 | + $tn_driver = is_array($payment) ? $payment['file'] : null; | |
| 43 | + | |
| 44 | + // transaction data validation callback | |
| 45 | + $tn_data_callback = function($data) use ($tn_driver) { | |
| 46 | + return (is_object($data) && isset($data->driver) && basename($data->driver, '.php') == basename($tn_driver, '.php')); | |
| 47 | + }; | |
| 48 | + // get previous transactions | |
| 49 | + $prev_tn_data = $history_obj->getEventsWithData(array('P0', 'PN'), $tn_data_callback); | |
| 50 | + | |
| 51 | + if (!is_array($prev_tn_data) || !count($prev_tn_data)) { | |
| 52 | + // no previous transactions found | |
| 53 | + VikError::raiseWarning('', 'No previous transactions found, unable to issue the refund'); | |
| 54 | + $mainframe->redirect('index.php?option=com_vikbooking&task=editorder&cid[]=' . $row['id']); | |
| 55 | + exit; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // load all previous refund events, if any | |
| 59 | + $refunds = $history_obj->getEventsWithData('RF', null, false); | |
| 60 | + $refunds = !is_array($refunds) ? array() : $refunds; | |
| 61 | + | |
| 62 | + $this->row = $row; | |
| 63 | + $this->payment = $payment; | |
| 64 | + $this->refunds = $refunds; | |
| 65 | + | |
| 66 | + // Display the template | |
| 67 | + parent::display($tpl); | |
| 68 | + } | |
| 69 | + | |
| 70 | +} | |