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 / site / helpers / libraries / statistics / widgets / finance / rog.php
vikappointments / site / helpers / libraries / statistics / widgets / finance Last commit date
coupons 1 month ago payments 1 month ago revenue 1 month ago index.html 1 month ago overall.php 1 month ago rog.php 1 month ago
rog.php
164 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 * Widget used to fetch the Rate of Growth between 2 months.
16 *
17 * @since 1.7
18 */
19 class VAPStatisticsWidgetFinanceRog extends VAPStatisticsWidget
20 {
21 /**
22 * Checks whether the specified group is supported by the widget.
23 *
24 * @param string $group The group to check.
25 *
26 * @return boolean True if supported, false otherwise.
27 */
28 public function isSupported($group)
29 {
30 return empty($group) || $group == '*' || $group == 'dashboard' || $group == 'finance';
31 }
32
33 /**
34 * Checks whether the specified user is capable to access this widget.
35 *
36 * @param JUser $user The user instance.
37 *
38 * @return boolean True if capable, false otherwise.
39 */
40 public function checkPermissions($user)
41 {
42 return $user->authorise('core.access.analytics.finance', 'com_vikappointments');
43 }
44
45 /**
46 * Override this method to return a configuration form of the widget.
47 *
48 * @return array
49 */
50 public function getForm()
51 {
52 return array(
53 /**
54 * The first month to fetch.
55 *
56 * The parameter is VOLATILE because, every time the session
57 * ends, we need to restore the field to an empty value, just
58 * to obtain the current date.
59 *
60 * @var select
61 */
62 'month1' => array(
63 'type' => 'select',
64 'label' => JText::translate('VAPMANAGERESTRINTERVALMONTH') . ' #1',
65 'default' => JHtml::fetch('date', 'now', 'n'),
66 'volatile' => true,
67 'options' => JHtml::fetch('vikappointments.months'),
68 ),
69
70 /**
71 * The first year to which the selected month belongs.
72 *
73 * The parameter is VOLATILE because, every time the session
74 * ends, we need to restore the field to an empty value, just
75 * to obtain the current date.
76 *
77 * @var select
78 */
79 'year1' => array(
80 'type' => 'select',
81 'label' => JText::translate('VAPMANAGERESTRINTERVALYEAR') . ' #1',
82 'default' => JHtml::fetch('date', 'now', 'Y'),
83 'volatile' => true,
84 'options' => JHtml::fetch('vikappointments.years', -10, 0),
85 ),
86
87 /**
88 * The second month to fetch.
89 *
90 * The parameter is VOLATILE because, every time the session
91 * ends, we need to restore the field to an empty value, just
92 * to obtain the current date.
93 *
94 * @var select
95 */
96 'month2' => array(
97 'type' => 'select',
98 'label' => JText::translate('VAPMANAGERESTRINTERVALMONTH') . ' #2',
99 'default' => JHtml::fetch('date', '-1 month', 'n'),
100 'volatile' => true,
101 'options' => JHtml::fetch('vikappointments.months'),
102 ),
103
104 /**
105 * The first year to which the selected month belongs.
106 *
107 * The parameter is VOLATILE because, every time the session
108 * ends, we need to restore the field to an empty value, just
109 * to obtain the current date.
110 *
111 * @var select
112 */
113 'year2' => array(
114 'type' => 'select',
115 'label' => JText::translate('VAPMANAGERESTRINTERVALYEAR') . ' #2',
116 'default' => JHtml::fetch('date', '-1 month', 'Y'),
117 'volatile' => true,
118 'options' => JHtml::fetch('vikappointments.years', -10, 0),
119 ),
120
121 /**
122 * When enabled, the total earning of the month will be proportionally
123 * estimated depending on the money already earned and the remaining
124 * days (applies only for the current month).
125 *
126 * @var checkbox
127 */
128 'prop' => array(
129 'type' => 'checkbox',
130 'label' => JText::translate('VAP_STATS_WIDGET_FINANCE_ROG_PROP_FIELD'),
131 'help' => JText::translate('VAP_STATS_WIDGET_FINANCE_ROG_PROP_FIELD_HELP'),
132 'default' => true,
133 ),
134 );
135 }
136
137 /**
138 * Loads the dataset(s) that will be recovered asynchronously
139 * for being displayed within the widget.
140 *
141 * It is possible to return an array of records to be passed
142 * to a chart or directly the HTML to replace.
143 *
144 * @return mixed
145 */
146 public function getData()
147 {
148 // fetch selected ranges
149 $a = $this->getOption('year1') . '-' . $this->getOption('month1');
150 $b = $this->getOption('year2') . '-' . $this->getOption('month2');
151
152 // import finance helper
153 VAPLoader::import('libraries.statistics.helpers.finance');
154 // fetch rog
155 $data = VAPStatisticsHelperFinance::getRog($a, $b, $this->getOption('prop'));
156
157 // replicate dates
158 $data['month1'] = $a;
159 $data['month2'] = $b;
160
161 return $data;
162 }
163 }
164