| 15540 |
efrain |
1 |
<?php
|
| 15808 |
anderson |
2 |
|
| 15540 |
efrain |
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 16768 |
efrain |
8 |
|
| 15540 |
efrain |
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use Laminas\View\Model\JsonModel;
|
|
|
13 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
14 |
use LeadersLinked\Mapper\DailyPulseRecordMapper;
|
|
|
15 |
use LeadersLinked\Model\DailyPulseRecord;
|
|
|
16 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
17 |
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
18 |
|
|
|
19 |
class DailyPulseReportsController extends AbstractActionController
|
|
|
20 |
{
|
|
|
21 |
/**
|
|
|
22 |
*
|
|
|
23 |
* @var AdapterInterface
|
|
|
24 |
*/
|
|
|
25 |
private $adapter;
|
| 16768 |
efrain |
26 |
|
| 15540 |
efrain |
27 |
/**
|
|
|
28 |
*
|
|
|
29 |
* @var LoggerInterface
|
|
|
30 |
*/
|
|
|
31 |
private $logger;
|
| 16768 |
efrain |
32 |
|
| 15540 |
efrain |
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var array
|
|
|
36 |
*/
|
|
|
37 |
private $config;
|
| 16768 |
efrain |
38 |
|
| 15540 |
efrain |
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @param AdapterInterface $adapter
|
|
|
42 |
* @param LoggerInterface $logger
|
|
|
43 |
* @param array $config
|
|
|
44 |
*/
|
| 16768 |
efrain |
45 |
public function __construct($adapter, $logger, $config)
|
| 15540 |
efrain |
46 |
{
|
| 16768 |
efrain |
47 |
$this->adapter = $adapter;
|
|
|
48 |
$this->logger = $logger;
|
|
|
49 |
$this->config = $config;
|
| 15540 |
efrain |
50 |
}
|
| 15808 |
anderson |
51 |
|
| 15540 |
efrain |
52 |
public function indexAction()
|
|
|
53 |
{
|
|
|
54 |
return new JsonModel([
|
|
|
55 |
'success' => false,
|
|
|
56 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
57 |
]);
|
|
|
58 |
}
|
| 15808 |
anderson |
59 |
|
| 15540 |
efrain |
60 |
public function overviewAction()
|
|
|
61 |
{
|
|
|
62 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
63 |
$currentUser = $currentUserPlugin->getUser();
|
| 15808 |
anderson |
64 |
|
| 15540 |
efrain |
65 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
66 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
| 15808 |
anderson |
67 |
|
| 15540 |
efrain |
68 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
69 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentNetwork->id);
|
| 15808 |
anderson |
70 |
|
| 15540 |
efrain |
71 |
$request = $this->getRequest();
|
| 16130 |
anderson |
72 |
if ($request->isGet()) {
|
| 15808 |
anderson |
73 |
|
| 16130 |
anderson |
74 |
$headers = $request->getHeaders();
|
| 15808 |
anderson |
75 |
|
| 16130 |
anderson |
76 |
$isJson = false;
|
|
|
77 |
if ($headers->has('Accept')) {
|
|
|
78 |
$accept = $headers->get('Accept');
|
| 15808 |
anderson |
79 |
|
| 16130 |
anderson |
80 |
$prioritized = $accept->getPrioritized();
|
| 15808 |
anderson |
81 |
|
| 16130 |
anderson |
82 |
foreach ($prioritized as $key => $value) {
|
|
|
83 |
$raw = trim($value->getRaw());
|
| 15808 |
anderson |
84 |
|
| 16130 |
anderson |
85 |
if (!$isJson) {
|
|
|
86 |
$isJson = strpos($raw, 'json');
|
|
|
87 |
}
|
| 15540 |
efrain |
88 |
}
|
|
|
89 |
}
|
| 15546 |
efrain |
90 |
|
| 15808 |
anderson |
91 |
|
| 16130 |
anderson |
92 |
if ($isJson) {
|
| 15808 |
anderson |
93 |
|
| 16130 |
anderson |
94 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
95 |
if (empty($startDate)) {
|
|
|
96 |
$startDate = date('Y-m-d');
|
|
|
97 |
}
|
| 15808 |
anderson |
98 |
|
|
|
99 |
|
| 16130 |
anderson |
100 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
101 |
if (empty($endDate)) {
|
|
|
102 |
$endDate = date('Y-m-d');
|
|
|
103 |
}
|
| 15808 |
anderson |
104 |
|
| 16130 |
anderson |
105 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
106 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
| 15808 |
anderson |
107 |
|
| 16130 |
anderson |
108 |
if (!$dtStartDate || !$dtEndDate) {
|
|
|
109 |
$startDate = date('Y-m-d');
|
|
|
110 |
$endDate = date('Y-m-d');
|
|
|
111 |
} else {
|
| 15945 |
anderson |
112 |
|
| 16130 |
anderson |
113 |
if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
114 |
$startDate = date('Y-m-d');
|
|
|
115 |
$endDate = date('Y-m-d');
|
|
|
116 |
}
|
|
|
117 |
}
|
| 15808 |
anderson |
118 |
|
| 16130 |
anderson |
119 |
$dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
|
|
|
120 |
$how_are_you_feel = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_HOW_ARE_YOU_FEEL, $startDate, $endDate);
|
| 15808 |
anderson |
121 |
|
| 16130 |
anderson |
122 |
$climate_on_your_organization = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_CLIMATE_ON_YOUR_ORGANIZATION, $startDate, $endDate);
|
| 15540 |
efrain |
123 |
|
| 15808 |
anderson |
124 |
|
|
|
125 |
|
| 16130 |
anderson |
126 |
$data = [
|
|
|
127 |
'labels' => [],
|
|
|
128 |
'users' => [
|
|
|
129 |
'how_are_you_feel' => [],
|
|
|
130 |
'climate_on_your_organization' => [],
|
|
|
131 |
],
|
|
|
132 |
'points' => [
|
|
|
133 |
'how_are_you_feel' => [],
|
|
|
134 |
'climate_on_your_organization' => [],
|
|
|
135 |
],
|
|
|
136 |
'average' => [
|
|
|
137 |
'how_are_you_feel' => [],
|
|
|
138 |
'climate_on_your_organization' => [],
|
|
|
139 |
],
|
|
|
140 |
'how_are_you_feel' => [
|
|
|
141 |
'average_points' => 0,
|
|
|
142 |
'average_users' => 0,
|
|
|
143 |
],
|
|
|
144 |
'climate_on_your_organization' => [
|
|
|
145 |
'average_points' => 0,
|
|
|
146 |
'average_users' => 0,
|
|
|
147 |
]
|
| 15808 |
anderson |
148 |
|
|
|
149 |
|
| 16130 |
anderson |
150 |
];
|
| 15544 |
efrain |
151 |
|
| 15808 |
anderson |
152 |
|
|
|
153 |
|
| 16130 |
anderson |
154 |
$how_are_you_feel_points = 0;
|
|
|
155 |
$how_are_you_feel_users = 0;
|
| 15808 |
anderson |
156 |
|
| 16130 |
anderson |
157 |
$climate_on_your_organization_points = 0;
|
|
|
158 |
$climate_on_your_organization_users = 0;
|
| 15808 |
anderson |
159 |
|
| 16130 |
anderson |
160 |
$count = 0;
|
| 15540 |
efrain |
161 |
|
|
|
162 |
|
| 16130 |
anderson |
163 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
164 |
do {
|
|
|
165 |
$count++;
|
|
|
166 |
$date = $dt->format('Y-m-d');
|
|
|
167 |
$label = $dt->format('d/m/Y');
|
| 15544 |
efrain |
168 |
|
| 16130 |
anderson |
169 |
array_push($data['labels'], $label);
|
| 15808 |
anderson |
170 |
|
|
|
171 |
|
| 16130 |
anderson |
172 |
$points = 0;
|
|
|
173 |
$users = 0;
|
|
|
174 |
foreach ($how_are_you_feel as $record) {
|
|
|
175 |
if ($date == $record['date']) {
|
|
|
176 |
$points = $record['points'];
|
|
|
177 |
$users = $record['users'];
|
|
|
178 |
}
|
|
|
179 |
}
|
| 15808 |
anderson |
180 |
|
|
|
181 |
|
|
|
182 |
|
| 16130 |
anderson |
183 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
184 |
array_push($data['users']['how_are_you_feel'], $users);
|
|
|
185 |
array_push($data['average']['how_are_you_feel'], $users ? $points / $users : 0);
|
| 15808 |
anderson |
186 |
|
|
|
187 |
|
| 16130 |
anderson |
188 |
$how_are_you_feel_points += $points;
|
|
|
189 |
$how_are_you_feel_users += $users;
|
| 15540 |
efrain |
190 |
|
| 16130 |
anderson |
191 |
$points = 0;
|
|
|
192 |
$users = 0;
|
|
|
193 |
foreach ($climate_on_your_organization as $record) {
|
|
|
194 |
if ($date == $record['date']) {
|
|
|
195 |
$points = $record['points'];
|
|
|
196 |
$users = $record['users'];
|
|
|
197 |
}
|
|
|
198 |
}
|
| 15808 |
anderson |
199 |
|
|
|
200 |
|
| 16130 |
anderson |
201 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
202 |
array_push($data['users']['climate_on_your_organization'], $users);
|
|
|
203 |
array_push($data['average']['climate_on_your_organization'], $users ? $points / $users : 0);
|
| 15808 |
anderson |
204 |
|
|
|
205 |
|
| 16130 |
anderson |
206 |
$climate_on_your_organization_points += $points;
|
|
|
207 |
$climate_on_your_organization_users += $users;
|
| 15808 |
anderson |
208 |
|
|
|
209 |
|
| 16130 |
anderson |
210 |
$dt->add(new \DateInterval('P1D'));
|
|
|
211 |
} while ($date < $endDate);
|
| 15808 |
anderson |
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
| 16130 |
anderson |
216 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
217 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
| 15808 |
anderson |
218 |
|
| 16130 |
anderson |
219 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
220 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
| 15540 |
efrain |
221 |
|
| 15546 |
efrain |
222 |
|
| 15808 |
anderson |
223 |
|
|
|
224 |
|
|
|
225 |
|
| 16130 |
anderson |
226 |
return new JsonModel([
|
|
|
227 |
'success' => true,
|
|
|
228 |
'data' => $data,
|
|
|
229 |
]);
|
|
|
230 |
} else {
|
|
|
231 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
232 |
$viewModel = new ViewModel();
|
|
|
233 |
$viewModel->setTemplate('leaders-linked/daily-pulse-reports/overview.phtml');
|
|
|
234 |
return $viewModel;
|
|
|
235 |
}
|
|
|
236 |
} else {
|
| 15945 |
anderson |
237 |
|
|
|
238 |
|
| 16130 |
anderson |
239 |
return new JsonModel([
|
|
|
240 |
'success' => false,
|
|
|
241 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
242 |
]);
|
|
|
243 |
}
|
| 15540 |
efrain |
244 |
}
|
| 15808 |
anderson |
245 |
|
| 15540 |
efrain |
246 |
public function overviewDownloadAction()
|
|
|
247 |
{
|
|
|
248 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
249 |
$currentUser = $currentUserPlugin->getUser();
|
| 15808 |
anderson |
250 |
|
| 15540 |
efrain |
251 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
252 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
| 15808 |
anderson |
253 |
|
| 15540 |
efrain |
254 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
255 |
$company = $companyMapper->fetchDefaultForNetworkByNetworkId($currentNetwork->id);
|
| 15808 |
anderson |
256 |
|
| 15540 |
efrain |
257 |
$request = $this->getRequest();
|
| 15808 |
anderson |
258 |
|
|
|
259 |
if ($request->isGet()) {
|
|
|
260 |
|
| 15540 |
efrain |
261 |
$startDate = $this->params()->fromQuery('startDate');
|
| 15808 |
anderson |
262 |
if (empty($startDate)) {
|
| 15540 |
efrain |
263 |
$startDate = date('Y-m-d');
|
|
|
264 |
}
|
| 15808 |
anderson |
265 |
|
|
|
266 |
|
| 15540 |
efrain |
267 |
$endDate = $this->params()->fromQuery('endDate');
|
| 15808 |
anderson |
268 |
if (empty($startDate)) {
|
| 15540 |
efrain |
269 |
$endDate = date('Y-m-d');
|
|
|
270 |
}
|
| 15808 |
anderson |
271 |
|
| 15541 |
efrain |
272 |
//$startDate = '2023-03-01';
|
|
|
273 |
//$endDate = '2023-03-19';
|
| 15808 |
anderson |
274 |
|
| 15540 |
efrain |
275 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
276 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
| 15808 |
anderson |
277 |
|
|
|
278 |
if (!$dtStartDate || !$dtEndDate) {
|
| 15540 |
efrain |
279 |
$startDate = date('Y-m-d');
|
|
|
280 |
$endDate = date('Y-m-d');
|
|
|
281 |
} else {
|
| 15808 |
anderson |
282 |
|
|
|
283 |
if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
| 15540 |
efrain |
284 |
$startDate = date('Y-m-d');
|
|
|
285 |
$endDate = date('Y-m-d');
|
|
|
286 |
}
|
|
|
287 |
}
|
| 15808 |
anderson |
288 |
|
| 15540 |
efrain |
289 |
$dailyPulseRecordMapper = DailyPulseRecordMapper::getInstance($this->adapter);
|
|
|
290 |
$how_are_you_feel = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_HOW_ARE_YOU_FEEL, $startDate, $endDate);
|
| 15808 |
anderson |
291 |
|
| 15540 |
efrain |
292 |
$climate_on_your_organization = $dailyPulseRecordMapper->fetchAllDataChartOrExcelByCompanyIdAndTypeAndDateRange($company->id, DailyPulseRecord::TYPE_CLIMATE_ON_YOUR_ORGANIZATION, $startDate, $endDate);
|
| 15808 |
anderson |
293 |
|
|
|
294 |
|
|
|
295 |
|
| 15540 |
efrain |
296 |
$data = [
|
| 15544 |
efrain |
297 |
'labels' => [],
|
| 15545 |
efrain |
298 |
'average' => [
|
|
|
299 |
'how_are_you_feel' => [],
|
|
|
300 |
'climate_on_your_organization' => [],
|
|
|
301 |
],
|
| 15544 |
efrain |
302 |
'users' => [
|
|
|
303 |
'how_are_you_feel' => [],
|
|
|
304 |
'climate_on_your_organization' => [],
|
|
|
305 |
],
|
|
|
306 |
'points' => [
|
|
|
307 |
'how_are_you_feel' => [],
|
|
|
308 |
'climate_on_your_organization' => [],
|
|
|
309 |
],
|
| 15540 |
efrain |
310 |
'how_are_you_feel' => [
|
| 15544 |
efrain |
311 |
'average_points' => 0,
|
|
|
312 |
'average_users' => 0,
|
| 15540 |
efrain |
313 |
],
|
|
|
314 |
'climate_on_your_organization' => [
|
|
|
315 |
'average_points' => 0,
|
|
|
316 |
'average_users' => 0,
|
|
|
317 |
]
|
| 15808 |
anderson |
318 |
|
|
|
319 |
|
| 15540 |
efrain |
320 |
];
|
| 15808 |
anderson |
321 |
|
|
|
322 |
|
|
|
323 |
|
| 15540 |
efrain |
324 |
$how_are_you_feel_points = 0;
|
|
|
325 |
$how_are_you_feel_users = 0;
|
| 15808 |
anderson |
326 |
|
| 15540 |
efrain |
327 |
$climate_on_your_organization_points = 0;
|
|
|
328 |
$climate_on_your_organization_users = 0;
|
| 15808 |
anderson |
329 |
|
| 15540 |
efrain |
330 |
$count = 0;
|
| 15808 |
anderson |
331 |
|
|
|
332 |
|
| 15540 |
efrain |
333 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
334 |
do {
|
|
|
335 |
$count++;
|
|
|
336 |
$date = $dt->format('Y-m-d');
|
|
|
337 |
$label = $dt->format('d/m/Y');
|
| 15808 |
anderson |
338 |
|
| 15544 |
efrain |
339 |
array_push($data['labels'], $label);
|
|
|
340 |
|
| 15808 |
anderson |
341 |
|
| 15544 |
efrain |
342 |
$points = 0;
|
|
|
343 |
$users = 0;
|
| 15808 |
anderson |
344 |
foreach ($how_are_you_feel as $record) {
|
|
|
345 |
if ($date == $record['date']) {
|
| 15544 |
efrain |
346 |
$points = $record['points'];
|
|
|
347 |
$users = $record['users'];
|
| 15540 |
efrain |
348 |
}
|
|
|
349 |
}
|
| 15808 |
anderson |
350 |
|
|
|
351 |
|
|
|
352 |
|
| 15544 |
efrain |
353 |
array_push($data['points']['how_are_you_feel'], $points);
|
|
|
354 |
array_push($data['users']['how_are_you_feel'], $users);
|
| 15545 |
efrain |
355 |
array_push($data['average']['how_are_you_feel'], $users ? $points / $users : 0);
|
| 15808 |
anderson |
356 |
|
|
|
357 |
|
| 15544 |
efrain |
358 |
$how_are_you_feel_points += $points;
|
|
|
359 |
$how_are_you_feel_users += $users;
|
| 15808 |
anderson |
360 |
|
| 15544 |
efrain |
361 |
$points = 0;
|
|
|
362 |
$users = 0;
|
| 15808 |
anderson |
363 |
foreach ($climate_on_your_organization as $record) {
|
|
|
364 |
if ($date == $record['date']) {
|
| 15544 |
efrain |
365 |
$points = $record['points'];
|
|
|
366 |
$users = $record['users'];
|
| 15540 |
efrain |
367 |
}
|
|
|
368 |
}
|
| 15808 |
anderson |
369 |
|
|
|
370 |
|
| 15544 |
efrain |
371 |
array_push($data['points']['climate_on_your_organization'], $points);
|
|
|
372 |
array_push($data['users']['climate_on_your_organization'], $users);
|
| 15545 |
efrain |
373 |
array_push($data['average']['climate_on_your_organization'], $users ? $points / $users : 0);
|
| 15808 |
anderson |
374 |
|
|
|
375 |
|
| 15544 |
efrain |
376 |
$climate_on_your_organization_points += $points;
|
|
|
377 |
$climate_on_your_organization_users += $users;
|
| 15808 |
anderson |
378 |
|
|
|
379 |
|
| 15540 |
efrain |
380 |
$dt->add(new \DateInterval('P1D'));
|
| 15808 |
anderson |
381 |
} while ($date < $endDate);
|
|
|
382 |
|
| 15540 |
efrain |
383 |
$data['how_are_you_feel']['average_points'] = number_format($how_are_you_feel_points / $count, 2);
|
|
|
384 |
$data['how_are_you_feel']['average_users'] = number_format($how_are_you_feel_users / $count, 2);
|
| 15808 |
anderson |
385 |
|
| 15540 |
efrain |
386 |
$data['climate_on_your_organization']['average_points'] = number_format($climate_on_your_organization_points / $count, 2);
|
|
|
387 |
$data['climate_on_your_organization']['average_users'] = number_format($climate_on_your_organization_users / $count, 2);
|
| 15808 |
anderson |
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
| 15540 |
efrain |
393 |
$spreadsheet = new Spreadsheet();
|
|
|
394 |
$spreadsheet->getProperties()->setTitle('Pulso Diario');
|
| 15808 |
anderson |
395 |
|
|
|
396 |
|
|
|
397 |
|
| 15540 |
efrain |
398 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
399 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
| 15808 |
anderson |
400 |
|
| 15540 |
efrain |
401 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Desde:');
|
|
|
402 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', $dt->format('d/m/Y'));
|
| 15808 |
anderson |
403 |
|
|
|
404 |
|
| 15540 |
efrain |
405 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
406 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Hasta:');
|
|
|
407 |
$spreadsheet->getActiveSheet()->SetCellValue('D1', $dt->format('d/m/Y'));
|
| 15808 |
anderson |
408 |
|
|
|
409 |
|
| 15540 |
efrain |
410 |
$spreadsheet->getActiveSheet()->SetCellValue('A3', 'Como te sientes hoy');
|
| 15544 |
efrain |
411 |
$spreadsheet->getActiveSheet()->setMergeCells(['A3', 'B3', 'C3', 'D3']);
|
| 15540 |
efrain |
412 |
$spreadsheet->getActiveSheet()->SetCellValue('A4', 'Puntos promedios');
|
|
|
413 |
$spreadsheet->getActiveSheet()->SetCellValue('B4', $data['how_are_you_feel']['average_points']);
|
|
|
414 |
$spreadsheet->getActiveSheet()->SetCellValue('C4', 'Usuarios promedios');
|
|
|
415 |
$spreadsheet->getActiveSheet()->SetCellValue('D4', $data['how_are_you_feel']['average_users']);
|
| 15808 |
anderson |
416 |
|
|
|
417 |
|
| 15540 |
efrain |
418 |
$spreadsheet->getActiveSheet()->SetCellValue('F3', 'Clima en su organización');
|
| 15544 |
efrain |
419 |
$spreadsheet->getActiveSheet()->setMergeCells(['F3', 'G3', 'H3', 'I3']);
|
| 15540 |
efrain |
420 |
$spreadsheet->getActiveSheet()->SetCellValue('F4', 'Puntos promedios');
|
|
|
421 |
$spreadsheet->getActiveSheet()->SetCellValue('G4', $data['climate_on_your_organization']['average_points']);
|
|
|
422 |
$spreadsheet->getActiveSheet()->SetCellValue('H4', 'Usuarios promedios');
|
|
|
423 |
$spreadsheet->getActiveSheet()->SetCellValue('I4', $data['climate_on_your_organization']['average_users']);
|
| 15808 |
anderson |
424 |
|
|
|
425 |
|
| 15544 |
efrain |
426 |
$spreadsheet->getActiveSheet()->SetCellValue('A6', 'Usuarios');
|
|
|
427 |
$spreadsheet->getActiveSheet()->setMergeCells(['A6', 'B6', 'C6']);
|
|
|
428 |
$spreadsheet->getActiveSheet()->SetCellValue('A7', 'Fecha');
|
|
|
429 |
$spreadsheet->getActiveSheet()->SetCellValue('B7', 'Puntos promedios');
|
|
|
430 |
$spreadsheet->getActiveSheet()->SetCellValue('C7', 'Cantidad de usuarios');
|
| 15808 |
anderson |
431 |
|
| 15544 |
efrain |
432 |
$row = 8;
|
|
|
433 |
$max = count($data['labels']);
|
| 15808 |
anderson |
434 |
|
|
|
435 |
for ($i = 0; $i < $max; $i++) {
|
| 15544 |
efrain |
436 |
$spreadsheet->getActiveSheet()->SetCellValue('A' . $row, $data['labels'][$i]);
|
|
|
437 |
$spreadsheet->getActiveSheet()->SetCellValue('B' . $row, $data['users']['how_are_you_feel'][$i]);
|
|
|
438 |
$spreadsheet->getActiveSheet()->SetCellValue('C' . $row, $data['users']['climate_on_your_organization'][$i]);
|
|
|
439 |
$row++;
|
| 15540 |
efrain |
440 |
}
|
| 15544 |
efrain |
441 |
|
| 15808 |
anderson |
442 |
|
| 15544 |
efrain |
443 |
$spreadsheet->getActiveSheet()->SetCellValue('F6', 'Puntos');
|
|
|
444 |
$spreadsheet->getActiveSheet()->setMergeCells(['F6', 'G6', 'H6']);
|
|
|
445 |
$spreadsheet->getActiveSheet()->SetCellValue('F7', 'Fecha');
|
|
|
446 |
$spreadsheet->getActiveSheet()->SetCellValue('G7', 'Puntos promedios');
|
|
|
447 |
$spreadsheet->getActiveSheet()->SetCellValue('H7', 'Cantidad de usuarios');
|
|
|
448 |
|
| 15808 |
anderson |
449 |
|
|
|
450 |
|
| 15544 |
efrain |
451 |
$row = 8;
|
|
|
452 |
$max = count($data['labels']);
|
| 15808 |
anderson |
453 |
|
|
|
454 |
for ($i = 0; $i < $max; $i++) {
|
| 15544 |
efrain |
455 |
$spreadsheet->getActiveSheet()->SetCellValue('F' . $row, $data['labels'][$i]);
|
|
|
456 |
$spreadsheet->getActiveSheet()->SetCellValue('G' . $row, $data['points']['how_are_you_feel'][$i]);
|
|
|
457 |
$spreadsheet->getActiveSheet()->SetCellValue('H' . $row, $data['points']['climate_on_your_organization'][$i]);
|
|
|
458 |
$row++;
|
| 15540 |
efrain |
459 |
}
|
| 15808 |
anderson |
460 |
|
| 15545 |
efrain |
461 |
$spreadsheet->getActiveSheet()->SetCellValue('J6', 'Puntos promedios ( puntos / usuarios ) ');
|
|
|
462 |
$spreadsheet->getActiveSheet()->setMergeCells(['J6', 'K6', 'L6']);
|
|
|
463 |
$spreadsheet->getActiveSheet()->SetCellValue('J7', 'Fecha');
|
|
|
464 |
$spreadsheet->getActiveSheet()->SetCellValue('K7', 'Puntos promedios');
|
|
|
465 |
$spreadsheet->getActiveSheet()->SetCellValue('L7', 'Cantidad de usuarios');
|
| 15808 |
anderson |
466 |
|
|
|
467 |
|
|
|
468 |
|
| 15545 |
efrain |
469 |
$row = 8;
|
|
|
470 |
$max = count($data['labels']);
|
| 15808 |
anderson |
471 |
|
|
|
472 |
for ($i = 0; $i < $max; $i++) {
|
| 15545 |
efrain |
473 |
$spreadsheet->getActiveSheet()->SetCellValue('J' . $row, $data['labels'][$i]);
|
|
|
474 |
$spreadsheet->getActiveSheet()->SetCellValue('K' . $row, number_format($data['average']['how_are_you_feel'][$i], 2));
|
|
|
475 |
$spreadsheet->getActiveSheet()->SetCellValue('L' . $row, number_format($data['average']['climate_on_your_organization'][$i], 2));
|
|
|
476 |
$row++;
|
|
|
477 |
}
|
| 15808 |
anderson |
478 |
|
|
|
479 |
|
| 15540 |
efrain |
480 |
$fileName = 'reporte_pulso_diario_' . date('d-m-Y-h-i-a', time()) . '.xls';
|
|
|
481 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_pulso_diario_' . time());
|
| 15808 |
anderson |
482 |
|
| 15540 |
efrain |
483 |
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
484 |
$writer->save($tempFilename);
|
| 15808 |
anderson |
485 |
|
| 15540 |
efrain |
486 |
$content = file_get_contents($tempFilename);
|
|
|
487 |
@unlink($tempFilename);
|
| 15808 |
anderson |
488 |
|
| 15540 |
efrain |
489 |
return new JsonModel([
|
|
|
490 |
'success' => true,
|
|
|
491 |
'data' => [
|
|
|
492 |
'content' => base64_encode($content),
|
|
|
493 |
'basename' => $fileName
|
| 15808 |
anderson |
494 |
|
| 15540 |
efrain |
495 |
]
|
|
|
496 |
]);
|
|
|
497 |
} else {
|
|
|
498 |
return new JsonModel([
|
|
|
499 |
'success' => false,
|
|
|
500 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
501 |
]);
|
|
|
502 |
}
|
|
|
503 |
}
|
|
|
504 |
}
|