PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
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
← All changes | admin/helpers/conditionalrules/payment_status.php +117 -0 1.6.1 → 1.8.16 View file →
@@ -1,0 +1,117 @@
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 +/**
14 + * Class handler for conditional rule "payment status".
15 + *
16 + * @since 1.16.0 (J) - 1.6.0 (WP)
17 + */
18 +class VikBookingConditionalRulePaymentStatus extends VikBookingConditionalRule
19 +{
20 + /**
21 + * Class constructor will define the rule name, description and identifier.
22 + */
23 + public function __construct()
24 + {
25 + // call parent constructor
26 + parent::__construct();
27 +
28 + $this->ruleName = JText::translate('VBO_HISTORY_GPM');
29 + $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_BOOKSTAT_DESCR');
30 + $this->ruleId = basename(__FILE__);
31 + }
32 +
33 + /**
34 + * Displays the rule parameters.
35 + *
36 + * @return void
37 + */
38 + public function renderParams()
39 + {
40 + $this->vbo_app->loadSelect2();
41 + $statuses = $this->getStatuses();
42 + $current_status = $this->getParam('statuses', '');
43 + ?>
44 + <div class="vbo-param-container">
45 + <div class="vbo-param-label"><?php echo JText::translate('VBSTATUS'); ?></div>
46 + <div class="vbo-param-setting">
47 + <select name="<?php echo $this->inputName('statuses'); ?>" id="<?php echo $this->inputID('statuses'); ?>">
48 + <option value=""></option>
49 + <?php
50 + foreach ($statuses as $ks => $vs) {
51 + ?>
52 + <option value="<?php echo $ks; ?>"<?php echo $current_status == $ks ? ' selected="selected"' : ''; ?>><?php echo $vs; ?></option>
53 + <?php
54 + }
55 + ?>
56 + </select>
57 + </div>
58 + </div>
59 +
60 + <script type="text/javascript">
61 + jQuery(function() {
62 + jQuery('#<?php echo $this->inputID('statuses'); ?>').select2();
63 + });
64 + </script>
65 + <?php
66 + }
67 +
68 + /**
69 + * Tells whether the rule is compliant.
70 + *
71 + * @return bool True on success, false otherwise.
72 + */
73 + public function isCompliant()
74 + {
75 + $book_status = $this->getPropVal('booking', 'status', '');
76 + $book_total = (float)$this->getPropVal('booking', 'total', 0);
77 + $book_totpaid = (float)$this->getPropVal('booking', 'totpaid', 0);
78 +
79 + $pay_status = $this->getParam('statuses', '');
80 +
81 + if (empty($pay_status) || empty($book_total)) {
82 + return false;
83 + }
84 +
85 + switch ($pay_status) {
86 + case 'fully_paid':
87 + return $book_status === 'confirmed' && $book_totpaid >= $book_total;
88 +
89 + case 'partially_paid':
90 + return $book_status === 'confirmed' && $book_totpaid > 0 && $book_totpaid < $book_total;
91 +
92 + case 'payment_received':
93 + return $book_status === 'confirmed' && $book_totpaid > 0;
94 +
95 + case 'to_be_paid':
96 + return $book_status === 'confirmed' && empty($book_totpaid);
97 +
98 + default:
99 + return false;
100 + }
101 + }
102 +
103 + /**
104 + * Internal function for this rule only.
105 + *
106 + * @return array
107 + */
108 + protected function getStatuses()
109 + {
110 + return [
111 + 'fully_paid' => JText::translate('VBOCOLORTAGRULECONFFIVE'),
112 + 'partially_paid' => JText::translate('VBOCOLORTAGRULECONFFOUR'),
113 + 'payment_received' => JText::translate('VBOBOOKHISTORYTP0'),
114 + 'to_be_paid' => JText::translate('VBOCOLORTAGRULECONFTHREE'),
115 + ];
116 + }
117 +}