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 / wizard / classes / taxes.php
vikappointments / site / helpers / libraries / wizard / classes Last commit date
employees.php 4 days ago index.html 4 days ago locations.php 4 days ago locwdays.php 4 days ago options.php 4 days ago packages.php 4 days ago payments.php 4 days ago services.php 4 days ago subscriptions.php 4 days ago syspack.php 4 days ago syssubscr.php 4 days ago system.php 4 days ago taxes.php 4 days ago
taxes.php
156 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 /**
15 * Implement the wizard step used to setup the taxes.
16 *
17 * @since 1.7.1
18 */
19 class VAPWizardStepTaxes extends VAPWizardStep
20 {
21 /**
22 * Returns the step title.
23 * Used as a very-short description.
24 *
25 * @return string The step title.
26 */
27 public function getTitle()
28 {
29 return JText::translate('VAPMENUTAXES');
30 }
31
32 /**
33 * Returns the step description.
34 *
35 * @return string The step description.
36 */
37 public function getDescription()
38 {
39 return JText::translate('VAP_WIZARD_STEP_TAXES_DESC');
40 }
41
42 /**
43 * Returns an optional step icon.
44 *
45 * @return string The step icon.
46 */
47 public function getIcon()
48 {
49 return '<i class="fas fa-calculator"></i>';
50 }
51
52 /**
53 * Return the group to which the step belongs.
54 *
55 * @return string The group name.
56 */
57 public function getGroup()
58 {
59 // belongs to GLOBAL group
60 return JText::translate('VAPMENUTITLEHEADER3');
61 }
62
63 /**
64 * Checks whether the step has been completed.
65 *
66 * @return boolean True if completed, false otherwise.
67 */
68 public function isCompleted()
69 {
70 // auto-complete in case of already created taxes
71 return (bool) $this->getTaxes();
72 }
73
74 /**
75 * Implements the step execution.
76 *
77 * @param JRegistry $data The request data.
78 *
79 * @return boolean
80 */
81 protected function doExecute($data)
82 {
83 $taxModel = JModelVAP::getInstance('tax');
84
85 // recover the specified percentage
86 $amount = abs((float) $data->get('amount'));
87
88 // register default taxes
89 $id_tax = $taxModel->save(array(
90 'name' => sprintf('VAT %s%%', $amount),
91 ));
92
93 if (!$id_tax)
94 {
95 // get latest registered error
96 $error = $taxModel->getError($index = null, $string = true);
97
98 // throw exception
99 throw new Exception($error ? $error : JText::translate('VAP_AJAX_GENERIC_ERROR'), 500);
100 }
101
102 $taxRuleModel = JModelVAP::getInstance('taxrule');
103
104 // register tax rule
105 $taxRuleModel->save(array(
106 'id_tax' => $id_tax,
107 'name' => 'VAT',
108 'operator' => $data->get('type'),
109 'amount' => $amount,
110 'apply' => 1,
111 ));
112
113 // register the created tax as default one
114 VAPFactory::getConfig()->set('deftax', $id_tax);
115
116 return true;
117 }
118
119 /**
120 * Checks whether the specified step can be skipped.
121 * By default, all the steps are mandatory.
122 *
123 * @return boolean True if skippable, false otherwise.
124 */
125 public function canIgnore()
126 {
127 return true;
128 }
129
130 /**
131 * Returns a list of created taxes.
132 *
133 * @return array A list of taxes.
134 */
135 public function getTaxes()
136 {
137 static $taxes = null;
138
139 // get taxes only once
140 if (is_null($taxes))
141 {
142 $dbo = JFactory::getDbo();
143
144 $q = $dbo->getQuery(true)
145 ->select($dbo->qn(array('id', 'name')))
146 ->from($dbo->qn('#__vikappointments_tax'))
147 ->order($dbo->qn('id') . ' ASC');
148
149 $dbo->setQuery($q);
150 $taxes = $dbo->loadObjectList();
151 }
152
153 return $taxes;
154 }
155 }
156