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