PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / taxestest / tmpl / default.php
vikappointments / admin / views / taxestest / tmpl Last commit date
default.php 1 month ago index.html 1 month ago
default.php
236 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 JHtml::fetch('vaphtml.assets.select2');
15 JHtml::fetch('vaphtml.assets.fontawesome');
16 JHtml::fetch('vaphtml.scripts.selectflags', '#vap-lang-sel', array('width' => '90%', 'allowClear' => true));
17
18 $args = $this->args;
19
20 $vik = VAPApplication::getInstance();
21
22 ?>
23
24 <div class="ratestest" style="padding: 10px;">
25
26 <form action="index.php" method="post" name="adminForm" id="adminForm">
27
28 <!-- MAIN -->
29
30 <div class="row-fluid">
31
32 <!-- SEARCH -->
33
34 <div class="span6 full-width">
35 <?php echo $vik->openEmptyFieldset(); ?>
36
37 <!-- TAX - Select -->
38
39 <?php
40 $taxes = JHtml::fetch('vaphtml.admin.taxes', $blank = '');
41
42 echo $vik->openControl(JText::translate('VAPTAXFIELDSET') . '*'); ?>
43 <select name="id_tax" id="vap-taxes-sel" class="required">
44 <?php echo JHtml::fetch('select.options', $taxes, 'value', 'text', $args['id_tax']); ?>
45 </select>
46 <?php echo $vik->closeControl(); ?>
47
48 <!-- AMOUNT -->
49
50 <?php echo $vik->openControl(JText::translate('VAPMANAGESUBSCR2') . '*'); ?>
51 <div class="input-prepend currency-field">
52 <button type="button" class="btn"><?php echo VAPFactory::getCurrency()->getSymbol(); ?></button>
53
54 <input type="number" name="amount" value="<?php echo $args['amount']; ?>" min="0" step="any" class="required" />
55 </div>
56 <?php echo $vik->closeControl(); ?>
57
58 <!-- LANGUAGE -->
59
60 <?php
61 $options = JHtml::fetch('contentlanguage.existing');
62
63 echo $vik->openControl(JText::translate('VAPLANGUAGE')); ?>
64 <select name="langtag" id="vap-lang-sel">
65 <option></option>
66 <?php echo JHtml::fetch('select.options', $options, 'value', 'text', $args['langtag']); ?>
67 </select>
68 <?php echo $vik->closeControl(); ?>
69
70 <!-- SUBMIT - Button -->
71
72 <?php echo $vik->openControl(''); ?>
73 <button type="button" class="btn" id="test-tax-btn">
74 <?php echo JText::translate('VAPTESTTAXES'); ?>
75 </button>
76 <?php echo $vik->closeControl(); ?>
77
78 <?php echo $vik->closeEmptyFieldset(); ?>
79 </div>
80
81 <!-- RESULT -->
82
83 <div class="span6" id="result-wrap" style="display: none;">
84 <?php echo $vik->openEmptyFieldset(); ?>
85
86 <table class="rates-table table" id="tax-table" style="display: none;">
87 <thead>
88 <tr>
89 <th><?php echo JText::translate('JDETAILS'); ?></th>
90 <th style="text-align: right;"><?php echo JText::translate('VAPMANAGESUBSCR2'); ?></th>
91 <th style="text-align: right;"><?php echo JText::translate('VAPCOUPONVALUETYPE2'); ?></th>
92 </tr>
93 </thead>
94
95 <tbody></tbody>
96
97 <tfoot></tfoot>
98 </table>
99
100 <?php echo $vik->closeEmptyFieldset(); ?>
101 </div>
102
103 </div>
104
105 </form>
106
107 </div>
108
109 <?php
110 JText::script('VAPCONNECTIONLOSTERROR');
111 JText::script('VAPINVTOTAL');
112 JText::script('VAPINVTAXES');
113 JText::script('VAPINVGRANDTOTAL');
114 ?>
115
116 <script>
117
118 var validator = new VikFormValidator('#adminForm');
119
120 jQuery(function($) {
121
122 $('#vap-taxes-sel').select2({
123 placeholder: '--',
124 allowClear: false,
125 width: '90%',
126 });
127
128 $('#test-tax-btn').on('click', function() {
129 $('#result-wrap').show();
130 $('#tax-table').hide();
131
132 if (!validator.validate()) {
133 return false;
134 }
135
136 $(this).attr('disabled', true);
137
138 UIAjax.do(
139 '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=tax.testajax'); ?>',
140 jQuery('#adminForm').serialize(),
141 (obj) => {
142 // for debug purposes
143 console.log(obj);
144
145 // build tax table
146 buildTaxTable(obj);
147
148 $(this).attr('disabled', false);
149 },
150 (err) => {
151 alert(Joomla.JText._('VAPCONNECTIONLOSTERROR'));
152
153 $(this).attr('disabled', false);
154 }
155 );
156 });
157
158 // helper function used to build the resulting table
159 const buildTaxTable = (data) => {
160 var table = $('#tax-table');
161 var tbody = table.find('tbody');
162 var tfoot = table.find('tfoot');
163
164 // reset body and footer contents
165 tbody.html('');
166 tfoot.html('');
167
168 // append total net to table body
169 tbody.append(createTableRow(Joomla.JText._('VAPINVTOTAL'), null, data.net));
170
171 let total = data.net;
172
173 // iterate breakdowns
174 data.breakdown.forEach((bd) => {
175 // increment net by the given taxes
176 total += parseFloat(bd.tax);
177
178 // append breakdown to body
179 tbody.append(createTableRow(bd.name, bd.tax, total, {class: 'rate-child'}));
180 });
181
182 // append total taxes to footer
183 tfoot.append(createTableRow(Joomla.JText._('VAPINVTAXES'), null, data.tax, {class: 'final-cost'}));
184 // append total gross to footer
185 tfoot.append(createTableRow(Joomla.JText._('VAPINVGRANDTOTAL'), null, data.gross, {class: 'final-cost'}));
186
187 table.show();
188 }
189
190 // helper function used to build a table row
191 const createTableRow = (details, cost, total, attrs) => {
192 const tr = $('<tr></tr>');
193
194 if (attrs) {
195 // set up row attributes
196 for (var k in attrs) {
197 tr.attr(k, attrs[k]);
198 }
199 }
200
201 const currency = VAPCurrency.getInstance();
202
203 // create details column
204 const detailsTD = $('<td></td>');
205 detailsTD.html(details);
206 detailsTD.css('text-align', 'left');
207
208 // create cost column
209 const costTD = $('<td></td>');
210 costTD.css('text-align', 'right');
211
212 if (cost !== null && cost !== undefined) {
213 costTD.html(currency.format(cost));
214 }
215
216 // create total column
217 const totalTD = $('<td></td>');
218 totalTD.css('text-align', 'right');
219 totalTD.addClass('rate-price');
220
221 if (total !== null && total !== undefined) {
222 totalTD.html(currency.format(total));
223 }
224
225 // build row
226 tr.append(detailsTD);
227 tr.append(costTD);
228 tr.append(totalTD);
229
230 return tr;
231 }
232
233 });
234
235 </script>
236