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 / models / empaccountstat.php
vikappointments / site / models Last commit date
allorders.php 2 days ago calendarweek.php 2 days ago cart.php 2 days ago confirmapp.php 2 days ago empaccountstat.php 2 days ago empattachser.php 2 days ago empcoupons.php 2 days ago empcustfields.php 2 days ago empeditcoupon.php 2 days ago empeditcustfield.php 2 days ago empeditlocation.php 2 days ago empeditpay.php 2 days ago empeditprofile.php 2 days ago empeditservice.php 2 days ago empeditwdays.php 2 days ago emplocations.php 2 days ago emplocwdays.php 2 days ago emplogin.php 2 days ago employeesearch.php 2 days ago employeeslist.php 2 days ago empmanres.php 2 days ago emppaylist.php 2 days ago empserviceslist.php 2 days ago empsettingsman.php 2 days ago empsubscrcart.php 2 days ago empsubscrhistory.php 2 days ago empsubscrorder.php 2 days ago empwdays.php 2 days ago index.html 2 days ago packages.php 2 days ago packagescart.php 2 days ago packagesconfirm.php 2 days ago packorders.php 2 days ago servicesearch.php 2 days ago serviceslist.php 2 days ago subscrcart.php 2 days ago subscrhistory.php 2 days ago subscrpayment.php 2 days ago
empaccountstat.php
218 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.mvc.model');
15
16 /**
17 * VikAppointments employee area account statistics view model.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsModelEmpaccountstat extends JModelVAP
22 {
23 /**
24 * The customer model instance.
25 *
26 * @var JModel
27 */
28 private $customerModel;
29
30 /**
31 * Loads the account details of the employee.
32 *
33 * @return array
34 */
35 public function getAccountData()
36 {
37 $auth = VAPEmployeeAuth::getInstance();
38
39 if (!$auth->isEmployee())
40 {
41 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
42 }
43
44 $data = array(
45 'active' => array(),
46 );
47
48 if ($auth->active_to == -1)
49 {
50 // lifetime license
51 $data['active']['value'] = JText::translate('VAPACCOUNTVALIDTHRU1');
52 $data['active']['class'] = 'active';
53 }
54 else if ($auth->active_to == 0)
55 {
56 // pending license
57 $data['active']['value'] = JText::translate('VAPACCOUNTVALIDTHRU2');
58 $data['active']['class'] = 'pending';
59 }
60 else
61 {
62 // format expiration date
63 $data['active']['value'] = JHtml::fetch('date', $auth->active_to_date, JText::translate('DATE_FORMAT_LC1'), $auth->timezone);
64
65 $now = JFactory::getDate();
66
67 // check whether the employee is still active
68 if ($now->toSql() > $auth->active_to_date)
69 {
70 // expired subscription
71 $data['active']['class'] = 'expired';
72 }
73 else
74 {
75 // calculate remaining days to expiration date
76 $days = VAPDateHelper::diff($auth->active_to_date, $now, 'days');
77
78 if ($days <= 7)
79 {
80 // close to expiration
81 $data['active']['class'] = 'pending';
82 }
83 else
84 {
85 // subscription active
86 $data['active']['class'] = 'active';
87 }
88 }
89 }
90
91 // register first activation date
92 if (!VAPDateHelper::isNull($auth->active_since))
93 {
94 $data['active']['since'] = JHtml::fetch('date', $auth->active_since, JText::translate('DATE_FORMAT_LC1'), $auth->timezone);
95 }
96 else
97 {
98 $data['active']['since'] = null;
99 }
100
101 // fetch appointments data
102 $data['appointments'] = $this->getAppointmentsData($auth);
103
104 return $data;
105 }
106
107 /**
108 * Fetches the overall appointments details.
109 *
110 * @param VAPEmployeeAuth $auth
111 *
112 * @return void
113 */
114 protected function getAppointmentsData(VAPEmployeeAuth $auth)
115 {
116 $dbo = JFactory::getDbo();
117
118 // get any approved codes
119 $approved = JHtml::fetch('vaphtml.status.find', 'code', array('appointments' => 1, 'approved' => 1));
120
121 $inner = $dbo->getQuery(true)
122 ->select('COUNT(1)')
123 ->from($dbo->qn('#__vikappointments_reservation', 'i'))
124 ->where($dbo->qn('i.id_employee') . ' = ' . $auth->id);
125
126 $q = $dbo->getQuery(true)
127 ->select('COUNT(1) AS ' . $dbo->qn('confirmed'))
128 ->select('SUM(' . $dbo->qn('r.total_cost') . ') AS ' . $dbo->qn('total'))
129 ->select('SUM(' . $dbo->qn('r.tot_paid') . ') AS ' . $dbo->qn('totalpaid'))
130 ->select('(' . $inner . ') AS ' . $dbo->qn('count'))
131 ->from($dbo->qn('#__vikappointments_reservation', 'r'))
132 ->where($dbo->qn('r.id_employee') . ' = ' . $auth->id)
133 ->where($dbo->qn('r.id_parent') . ' > 0');
134
135 if ($approved)
136 {
137 // filter by approved status
138 $q->where($dbo->qn('r.status') . ' IN (' . implode(',', array_map(array($dbo, 'q'), $approved)) . ')');
139 }
140
141 $dbo->setQuery($q);
142
143 if ($data = $dbo->loadAssoc())
144 {
145 return $data;
146 }
147
148 return array(
149 'confirmed' => 0,
150 'total' => 0,
151 'totalpaid' => 0,
152 'count' => 0,
153 );
154 }
155
156 /**
157 * Loads a list of customers to be displayed within the
158 * employees area view.
159 *
160 * @param array &$filters An array of filters.
161 * @param array &$options An array of options, such as the ordering mode.
162 *
163 * @return array A list of customers.
164 */
165 public function getCustomers(array &$filters = array(), array &$options = array())
166 {
167 $auth = VAPEmployeeAuth::getInstance();
168
169 if (!$auth->isEmployee())
170 {
171 // raise error in case of no employee
172 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
173 }
174
175 // search customers through model
176 $this->customerModel = JModelVAP::getInstance('customer');
177
178 // take only the customers assigned to this employee
179 $options['id_employee'] = $auth->id;
180
181 // load customers
182 return array_values($this->customerModel->search($filters['search'], $options));
183 }
184
185 /**
186 * Returns the list pagination.
187 *
188 * @param array $filters An array of filters.
189 * @param array $options An array of options.
190 *
191 * @return JPagination
192 */
193 public function getPagination(array $filters = array(), array $options = array())
194 {
195 if (!$this->customerModel)
196 {
197 throw new RuntimeException('Model not set', 500);
198 }
199
200 return $this->customerModel->getPagination($filters, $options);
201 }
202
203 /**
204 * Returns the total number of employees matching the search query.
205 *
206 * @return integer
207 */
208 public function getTotal()
209 {
210 if (!$this->customerModel)
211 {
212 throw new RuntimeException('Model not set', 500);
213 }
214
215 return $this->customerModel->getTotal();
216 }
217 }
218