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