PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / tax / rules / add.php
vikappointments / site / helpers / libraries / tax / rules Last commit date
add.php 5 days ago index.html 5 days ago sub.php 5 days ago vat.php 5 days ago
add.php
67 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 VAPLoader::import('libraries.tax.rule');
15
16 /**
17 * Tax rule percentage SUM calculator.
18 *
19 * @since 1.7
20 */
21 class VAPTaxRuleAdd extends VAPTaxRule
22 {
23 /**
24 * Calculates the taxes for the specified amount.
25 *
26 * @param float $total The total amount to use.
27 * @param object $data An object containing the tax details.
28 * @param array $options An array of options.
29 *
30 * @return void
31 */
32 public function calculate($total, $data, array $options = array())
33 {
34 // check whether we should apply the calculation
35 // to the base cost (1) or on cascade (2)
36 $apply = (int) $this->get('apply');
37
38 if ($apply == 2)
39 {
40 // apply to total gross
41 $total = $data->gross;
42 }
43
44 // get specified tax amount
45 $tax = (float) $this->get('amount', 0.0);
46
47 // calculate resulting taxes
48 $tax = round($total * $tax / 100, 2, PHP_ROUND_HALF_UP);
49
50 // make sure the calculated taxes do not exceed
51 // the specified threshold (TAX CAP)
52 $cap = (float) $this->get('cap', 0);
53
54 if ($cap > 0)
55 {
56 $tax = min(array($tax, $cap));
57 }
58
59 // update resulting data
60 $data->tax += $tax;
61 $data->gross += $tax;
62
63 // merge breakdown
64 $this->addBreakdown($tax, $data->breakdown);
65 }
66 }
67