File manager - Edit - /home/verseaumee/ptitsanes/plugins/solidres/invoice/components/com_solidres/models/customerinvoices.php
Back
<?php /* ------------------------------------------------------------------------ Solidres - Hotel booking extension for Joomla ------------------------------------------------------------------------ @Author Solidres Team @Website http://www.solidres.com @Copyright Copyright (C) 2013 - 2016 Solidres. All Rights Reserved. @License GNU General Public License version 3, or later ------------------------------------------------------------------------ */ defined('_JEXEC') or die; use Joomla\Registry\Registry; class SolidresModelCustomerInvoices extends JModelList { protected $payments = array(); public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( 'id', 'a.id', 'invoice_date', 'a.invoice_date', 'filename', 'a.filename', 'sent_on', 'a.sent_on', 'invoice_number', 'a.invoice_number', 'created_date', 'a.created_date', 'created_by', 'a.created_by', 'modified_date', 'a.modified_date', 'modified_by', 'a.modified_by', 'reservation_id', 'a.reservation_id', 'reservation_code', 'customer_name', 'reservation_asset_name', 'a2.reservation_asset_name', 'reservation_asset_id', 'a2.reservation_asset_id', 'grand_total', 'a2.payment_status', ); } parent::__construct($config); } protected function populateState($ordering = null, $direction = null) { $value = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'); $this->setState('filter.search', $value); $value = $this->getUserStateFromRequest($this->context . '.filter.created_date', 'filter_created_date', '', 'string'); $this->setState('filter.created_date', $value); $value = $this->getUserStateFromRequest($this->context . '.filter.payment_status', 'filter_payment_status', '', 'string'); $this->setState('filter.payment_status', $value); parent::populateState('a.id', 'desc'); } protected function getStoreId($id = '') { $id .= ':' . $this->getState('filter.search'); $id .= ':' . $this->getState('filter.created_date'); $id .= ':' . $this->getState('filter.payment_status'); return parent::getStoreId($id); } protected function getListQuery() { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select($this->getState('list.select', 'a.id, a.invoice_date, a.filename, a.html, a.sent_on, ' . 'a.invoice_number, a.created_date, a.created_by, a.modified_date, a.modified_by, a.reservation_id, ' . 'a2.code AS reservation_code, a2.payment_status, CONCAT_WS(' . $db->quote(' ') . ', a2.customer_firstname, a2.customer_middlename, a2.customer_lastname) AS customer_name, ' . ' a2.state AS reservation_status, a2.reservation_asset_id, a2.reservation_asset_name, a2.currency_id, ' . ' ( CASE WHEN a2.discount_pre_tax = 1 THEN a2.total_price_tax_excl - a2.total_discount + a2.tax_amount + a2.total_extra_price_tax_incl ELSE a2.total_price_tax_excl + a2.tax_amount - a2.total_discount + a2.total_extra_price_tax_incl END + a2.tourist_tax_amount + a2.payment_method_surcharge - a2.payment_method_discount ) AS grand_total, a2.total_paid' )) ->from($db->quoteName('#__sr_invoices', 'a')) ->innerJoin($db->quoteName('#__sr_reservations', 'a2') . ' ON a2.id = a.reservation_id') ->innerJoin($db->quoteName('#__sr_reservation_assets', 'a3') . ' ON a3.id = a2.reservation_asset_id') ->innerJoin($db->quoteName('#__sr_customers', 'a4') . ' ON a4.id = a2.customer_id') ->where('a4.user_id = ' . (int) JFactory::getUser()->id); $search = $this->getState('filter.search'); if (!empty($search)) { if (strpos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%')); $query->where('(a.invoice_number LIKE ' . $search . ' OR a2.code LIKE ' . $search . ')'); } } $createdDate = $this->getState('filter.created_date'); if (!empty($createdDate)) { $createdDate = preg_replace('/\s+.*/', '', $createdDate); $date = DateTime::createFromFormat('Y-m-d', $createdDate); if ($date && $date->format('Y-m-d') === $createdDate) { $query->where('DATE(a.created_date) = ' . $db->quote($createdDate)); } } $paymentStatus = $this->getState('filter.payment_status'); if (is_numeric($paymentStatus)) { $query->where('a2.payment_status = ' . (int) $paymentStatus); } $ordering = $this->getState('list.ordering', 'a.id'); $direction = $this->getState('list.direction', 'desc'); $query->order($db->escape($ordering) . ' ' . $db->escape($direction)); return $query; } public function getPayments($reservationAssetId) { $app = JFactory::getApplication(); $db = $this->getDbo(); $query = $db->getQuery(true) ->select('a.element') ->from($db->quoteName('#__extensions', 'a')) ->where('a.enabled = 1') ->where('a.type = ' . $db->quote('plugin')) ->where('a.folder = ' . $db->quote('solidrespayment')); $db->setQuery($query); $payments = array(); if ($elements = $db->loadColumn()) { foreach ($elements as $element) { $element = strtolower($element); $payment = new stdClass; $payment->config = new Registry; $payment->element = $element; $query->clear() ->select('a.data_key, a.data_value') ->from($db->quoteName('#__sr_config_data', 'a')) ->where('a.data_key LIKE ' . $db->quote('payments/' . $element . '/%')) ->where('a.scope_id = ' . (int) $reservationAssetId); $db->setQuery($query); if ($rows = $db->loadObjectList()) { JLoader::register('SRPayment', SRPATH_LIBRARY . '/payment/payment.php'); JPluginHelper::importPlugin('solidrespayment'); $language = JFactory::getLanguage(); foreach ($rows as $row) { $class = 'PlgSolidrespayment' . ucfirst($element); if (!defined($class . '::PAY_INVOICE') || !constant($class . '::PAY_INVOICE')) { continue; } $name = str_replace('payments/' . $element . '/' . $element . '_', '', $row->data_key); $value = $row->data_value; if (is_string($value) && is_array(json_decode($value, true)) && (json_last_error() == JSON_ERROR_NONE) ) { $value = json_decode($value, true); } $payment->config->set($row->data_key, $row->data_value); $payment->config->set($name, $value); } $language->load('plg_solidrespayment_' . $element, JPATH_PLUGINS . '/solidrespayment/' . $element); $payment->field = ''; if (SRPayment::hasCardForm($payment->element)) { $payment->field = SRLayoutHelper::render('payment.cardform', [ 'checked' => false, 'hideCheckbox' => true, 'reservationDetails' => [], 'element' => $payment->element, 'solidresPaymentConfigData' => $payment->config, ] ); } try { $results = $app->triggerEvent('onSolidrespaymentInvoice' . ucfirst($element) . 'AfterCard', array($payment)); $payment->field .= trim(join(PHP_EOL, $results)); } catch (RuntimeException $e) { } } $payments[] = $payment; } } return $payments; } public function getPaymentAmount($resTable) { if ($resTable->discount_pre_tax) { $grandTotal = $resTable->total_price_tax_excl - $resTable->total_discount + $resTable->tax_amount + $resTable->total_extra_price_tax_incl; } else { $grandTotal = $resTable->total_price_tax_excl + $resTable->tax_amount - $resTable->total_discount + $resTable->total_extra_price_tax_incl; } if ($resTable->tourist_tax_amount) { $grandTotal += $resTable->tourist_tax_amount; } else { $grandTotal += $resTable->payment_method_surcharge; } if ($resTable->payment_method_discount > 0) { $grandTotal -= $resTable->payment_method_discount; } return $grandTotal - $resTable->total_paid; } }
| ver. 1.4 |
Github
|
.
| PHP 8.5.7 | Generation time: 0 |
proxy
|
phpinfo
|
Settings