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