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