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 / vat.php
vikappointments / site / helpers / libraries / tax / rules Last commit date
add.php 6 days ago index.html 6 days ago sub.php 6 days ago vat.php 6 days ago
vat.php
62 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 VAT calculator (included taxes).
18 *
19 * @since 1.7
20 */
21 class VAPTaxRuleVAT 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 // get specified tax amount
35 $tax = (float) $this->get('amount', 0.0);
36
37 // DO NOT take care of "apply" parameter, because
38 // inclusive taxes can be calculated only on the
39 // base total gross
40
41 // calculate resulting VAT
42 $tax = round($data->gross - $data->gross / (1 + $tax / 100), 2, PHP_ROUND_HALF_UP);
43
44 // make sure the calculated taxes do not exceed
45 // the specified threshold (TAX CAP)
46 $cap = (float) $this->get('cap', 0);
47
48 if ($cap > 0)
49 {
50 $tax = min(array($tax, $cap));
51 }
52
53 // sub to taxes
54 $data->tax += $tax;
55 // subtract from net
56 $data->net -= $tax;
57
58 // merge breakdown
59 $this->addBreakdown($tax, $data->breakdown);
60 }
61 }
62