| 15670 |
anderson |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
| 16758 |
efrain |
7 |
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 16768 |
efrain |
9 |
|
| 16758 |
efrain |
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\Mvc\I18n\Translator;
|
|
|
13 |
|
| 15682 |
anderson |
14 |
use Laminas\View\Model\JsonModel;
|
|
|
15 |
use Laminas\View\Model\ViewModel;
|
| 15718 |
anderson |
16 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
17 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
18 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
| 16758 |
efrain |
19 |
use Laminas\Db\Sql\Expression;
|
|
|
20 |
use LeadersLinked\Mapper\DiscoveryContactInteractionMapper;
|
|
|
21 |
use LeadersLinked\Mapper\DiscoveryContactInteractionTypeMapper;
|
|
|
22 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
23 |
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
| 15670 |
anderson |
24 |
|
| 16758 |
efrain |
25 |
|
| 15670 |
anderson |
26 |
// Create an action controller.
|
|
|
27 |
class DiscoveryContactProgressController extends AbstractActionController
|
|
|
28 |
{
|
| 15682 |
anderson |
29 |
/**
|
|
|
30 |
*
|
| 16769 |
efrain |
31 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
| 15682 |
anderson |
32 |
*/
|
|
|
33 |
private $adapter;
|
| 16758 |
efrain |
34 |
|
| 15682 |
anderson |
35 |
/**
|
|
|
36 |
*
|
| 16769 |
efrain |
37 |
* @var \LeadersLinked\Cache\CacheInterface
|
| 15682 |
anderson |
38 |
*/
|
| 16769 |
efrain |
39 |
private $cache;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var \Laminas\Log\LoggerInterface
|
|
|
45 |
*/
|
| 15682 |
anderson |
46 |
private $logger;
|
| 16758 |
efrain |
47 |
|
| 15682 |
anderson |
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var array
|
|
|
51 |
*/
|
|
|
52 |
private $config;
|
| 16758 |
efrain |
53 |
|
| 16769 |
efrain |
54 |
|
| 15682 |
anderson |
55 |
/**
|
|
|
56 |
*
|
| 16769 |
efrain |
57 |
* @var \Laminas\Mvc\I18n\Translator
|
| 16758 |
efrain |
58 |
*/
|
|
|
59 |
private $translator;
|
|
|
60 |
|
| 16769 |
efrain |
61 |
|
| 16758 |
efrain |
62 |
/**
|
|
|
63 |
*
|
| 16769 |
efrain |
64 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
65 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
66 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
| 15682 |
anderson |
67 |
* @param array $config
|
| 16769 |
efrain |
68 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
| 15682 |
anderson |
69 |
*/
|
| 16769 |
efrain |
70 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
| 15682 |
anderson |
71 |
{
|
|
|
72 |
$this->adapter = $adapter;
|
| 16769 |
efrain |
73 |
$this->cache = $cache;
|
| 15682 |
anderson |
74 |
$this->logger = $logger;
|
|
|
75 |
$this->config = $config;
|
| 16758 |
efrain |
76 |
$this->translator = $translator;
|
| 15682 |
anderson |
77 |
}
|
|
|
78 |
|
| 15670 |
anderson |
79 |
|
| 15678 |
anderson |
80 |
|
| 15679 |
anderson |
81 |
|
| 15788 |
anderson |
82 |
public function indexAction()
|
|
|
83 |
{
|
| 15792 |
anderson |
84 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 16758 |
efrain |
85 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
86 |
|
| 15796 |
anderson |
87 |
$request = $this->getRequest();
|
| 15793 |
anderson |
88 |
|
| 16305 |
anderson |
89 |
if ($request->isGet()) {
|
|
|
90 |
$headers = $request->getHeaders();
|
|
|
91 |
$isJson = false;
|
| 15795 |
anderson |
92 |
|
| 16305 |
anderson |
93 |
if ($headers->has('Accept')) {
|
|
|
94 |
$accept = $headers->get('Accept');
|
| 15796 |
anderson |
95 |
|
| 16305 |
anderson |
96 |
$prioritized = $accept->getPrioritized();
|
| 15796 |
anderson |
97 |
|
| 16305 |
anderson |
98 |
foreach ($prioritized as $key => $value) {
|
|
|
99 |
$raw = trim($value->getRaw());
|
| 15796 |
anderson |
100 |
|
| 16305 |
anderson |
101 |
if (!$isJson) {
|
|
|
102 |
$isJson = strpos($raw, 'json');
|
|
|
103 |
}
|
| 15796 |
anderson |
104 |
}
|
|
|
105 |
}
|
| 16758 |
efrain |
106 |
|
|
|
107 |
|
|
|
108 |
//$isJson = true;
|
| 16305 |
anderson |
109 |
if ($isJson) {
|
| 16241 |
anderson |
110 |
|
| 16305 |
anderson |
111 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
112 |
if (empty($startDate)) {
|
|
|
113 |
$startDate = date('Y-m-d');
|
|
|
114 |
}
|
| 15798 |
anderson |
115 |
|
| 16305 |
anderson |
116 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
117 |
if (empty($endDate)) {
|
|
|
118 |
$endDate = date('Y-m-d');
|
|
|
119 |
}
|
| 16758 |
efrain |
120 |
|
| 16305 |
anderson |
121 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
122 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
| 16758 |
efrain |
123 |
|
| 15800 |
anderson |
124 |
|
| 16758 |
efrain |
125 |
|
| 16305 |
anderson |
126 |
if (!$dtStartDate || !$dtEndDate) {
|
|
|
127 |
$startDate = date('Y-m-d');
|
|
|
128 |
$endDate = date('Y-m-d');
|
|
|
129 |
} else {
|
| 16125 |
anderson |
130 |
|
| 16305 |
anderson |
131 |
if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
132 |
$startDate = date('Y-m-d');
|
|
|
133 |
$endDate = date('Y-m-d');
|
|
|
134 |
}
|
| 16758 |
efrain |
135 |
|
| 16305 |
anderson |
136 |
}
|
| 16758 |
efrain |
137 |
|
|
|
138 |
//echo ' $startDate = ' . $startDate . ' $endDate = ' . $endDate; exit;
|
|
|
139 |
|
|
|
140 |
$graph = [];
|
|
|
141 |
|
| 15806 |
anderson |
142 |
|
| 16758 |
efrain |
143 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
144 |
|
|
|
145 |
do {
|
|
|
146 |
$tempDate = $dt->format('Y-m-d');
|
|
|
147 |
$graph[ $tempDate ] = ['label' => $dt->format('d/m/Y'), 'value' => 0];
|
|
|
148 |
$dt->add(new \DateInterval('P1D'));
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
} while($endDate > $tempDate);
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
155 |
|
|
|
156 |
/*
|
|
|
157 |
select count(*) as cant, date(added_on) as date from tbl_discovery_contacts
|
|
|
158 |
where date(added_on) BETWEEN '2023-05-05' AND '2023-05-31'
|
|
|
159 |
group by date(added_on)
|
|
|
160 |
order by date ASC
|
|
|
161 |
*/
|
|
|
162 |
|
|
|
163 |
$select = $queryMapper->getSql()->select(DiscoveryContactMapper::_TABLE);
|
|
|
164 |
$select->columns([
|
|
|
165 |
'total' => new Expression('COUNT(*)'),
|
|
|
166 |
'date' => new Expression('DATE(added_on)'),
|
|
|
167 |
]);
|
|
|
168 |
$select->where->between( new Expression('DATE(added_on)') , $startDate, $endDate);
|
|
|
169 |
$select->group(new Expression('DATE(added_on)'));
|
|
|
170 |
$select->order('date ASC');
|
|
|
171 |
|
|
|
172 |
$records = $queryMapper->fetchAll($select);
|
|
|
173 |
foreach($records as $record)
|
|
|
174 |
{
|
| 16558 |
anderson |
175 |
|
| 16758 |
efrain |
176 |
$graph[ $record['date'] ][ 'value' ] = $record['total'];
|
| 16552 |
anderson |
177 |
}
|
| 16758 |
efrain |
178 |
|
|
|
179 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
180 |
$discoveryContactInteractionType = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($currentCompany->id);
|
|
|
181 |
if(!$discoveryContactInteractionType) {
|
|
|
182 |
$discoveryContactInteractionType = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($currentCompany->id);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
/*
|
|
|
187 |
select count(*), user_id, date(added_on) as date from tbl_discovery_contact_interactions
|
|
|
188 |
where interaction_type_id = 1 and date(added_on) BETWEEN '2023-05-05' AND '2023-05-31'
|
|
|
189 |
group by date(added_on), user_id
|
|
|
190 |
order by date
|
|
|
191 |
*/
|
|
|
192 |
|
|
|
193 |
$table = [];
|
|
|
194 |
$select = $queryMapper->getSql()->select(DiscoveryContactInteractionMapper::_TABLE);
|
|
|
195 |
$select->columns([
|
|
|
196 |
'user_id',
|
|
|
197 |
'total' => new Expression('COUNT(*)'),
|
|
|
198 |
'date' => new Expression('DATE(added_on)'),
|
|
|
199 |
]);
|
|
|
200 |
$select->where->equalTo('interaction_type_id', $discoveryContactInteractionType->id);
|
|
|
201 |
$select->where->between( new Expression('DATE(added_on)') , $startDate, $endDate);
|
|
|
202 |
$select->group([ new Expression('DATE(added_on)'), 'user_id']);
|
|
|
203 |
$select->order('date ASC');
|
|
|
204 |
|
|
|
205 |
$records = $queryMapper->fetchAll($select);
|
|
|
206 |
foreach($records as $record)
|
|
|
207 |
{
|
|
|
208 |
$user_id = $record['user_id'];
|
|
|
209 |
|
|
|
210 |
if(!isset( $table[ $user_id ])) {
|
|
|
211 |
|
|
|
212 |
$items = [];
|
|
|
213 |
|
|
|
214 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
215 |
|
|
|
216 |
do {
|
|
|
217 |
$tempDate = $dt->format('Y-m-d');
|
|
|
218 |
$items[ $tempDate ] = ['label' => $dt->format('d/m/Y'), 'value' => 0];
|
|
|
219 |
$dt->add(new \DateInterval('P1D'));
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
} while($endDate > $tempDate);
|
|
|
223 |
|
|
|
224 |
$table[ $user_id ] = $items;
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
$table[ $user_id ][ $record['date'] ]['value'] = $record['total'];
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
$records = array_values($graph);
|
|
|
234 |
|
|
|
235 |
$labels = [];
|
|
|
236 |
$values = [];
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
foreach($records as $record)
|
|
|
241 |
{
|
|
|
242 |
array_push($labels, $record['label']);
|
|
|
243 |
array_push($values, $record['value']);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
$graph = [
|
|
|
247 |
'labels' => $labels,
|
|
|
248 |
'values' => $values
|
| 16538 |
anderson |
249 |
];
|
| 16758 |
efrain |
250 |
|
|
|
251 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
$first = true;
|
|
|
255 |
$labels = [];
|
|
|
256 |
$users = [];
|
|
|
257 |
|
|
|
258 |
$records = $table;
|
|
|
259 |
foreach($records as $user_id => $items)
|
|
|
260 |
{
|
|
|
261 |
$user = $userMapper->fetchOne($user_id);
|
|
|
262 |
if(!$user) {
|
|
|
263 |
continue;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
$values = [];
|
|
|
268 |
foreach($items as $item)
|
|
|
269 |
{
|
|
|
270 |
if($first) {
|
|
|
271 |
array_push($labels,['date' => $item['label'] ]);
|
|
|
272 |
}
|
|
|
273 |
array_push($values,['value' => $item['value'] ]);
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
array_push($users, [
|
|
|
277 |
'first_name' => $user->first_name,
|
|
|
278 |
'last_name' => $user->last_name,
|
|
|
279 |
'email' => $user->email,
|
|
|
280 |
'values' => $values,
|
|
|
281 |
]);
|
|
|
282 |
|
|
|
283 |
$first = false;
|
|
|
284 |
|
| 16305 |
anderson |
285 |
}
|
| 16758 |
efrain |
286 |
|
|
|
287 |
|
|
|
288 |
usort($users, function($a, $b) {
|
|
|
289 |
|
|
|
290 |
$result = $a['first_name'] <=> $b['last_name'];
|
|
|
291 |
if($result === 0) {
|
|
|
292 |
$a['last_name'] <=> $b['last_name'];
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
return $result;
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
});
|
|
|
299 |
|
|
|
300 |
$table = [
|
|
|
301 |
'labels' => $labels,
|
|
|
302 |
'users' => $users,
|
|
|
303 |
];
|
| 15842 |
anderson |
304 |
|
| 16758 |
efrain |
305 |
|
| 16305 |
anderson |
306 |
return new JsonModel([
|
|
|
307 |
'success' => true,
|
| 16758 |
efrain |
308 |
'data' => [
|
|
|
309 |
'graph' => $graph,
|
|
|
310 |
'table' => $table,
|
|
|
311 |
],
|
|
|
312 |
|
| 16305 |
anderson |
313 |
]);
|
|
|
314 |
} else {
|
|
|
315 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
316 |
$viewModel = new ViewModel();
|
|
|
317 |
$viewModel->setTemplate('leaders-linked/discovery-contact-progress/index.phtml');
|
|
|
318 |
return $viewModel;
|
|
|
319 |
}
|
|
|
320 |
}
|
| 16758 |
efrain |
321 |
|
|
|
322 |
return new JsonModel([
|
|
|
323 |
'success' => false,
|
|
|
324 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
325 |
]);
|
| 15670 |
anderson |
326 |
}
|
| 16758 |
efrain |
327 |
|
|
|
328 |
public function downloadAction()
|
|
|
329 |
{
|
|
|
330 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
331 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
332 |
|
|
|
333 |
$request = $this->getRequest();
|
|
|
334 |
|
|
|
335 |
if ($request->isGet()) {
|
|
|
336 |
$startDate = $this->params()->fromQuery('startDate');
|
|
|
337 |
if (empty($startDate)) {
|
|
|
338 |
$startDate = date('Y-m-d');
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
$endDate = $this->params()->fromQuery('endDate');
|
|
|
342 |
if (empty($endDate)) {
|
|
|
343 |
$endDate = date('Y-m-d');
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
$dtStartDate = \DateTime::createFromFormat('Y-n-d', $startDate);
|
|
|
347 |
$dtEndDate = \DateTime::createFromFormat('Y-n-d', $endDate);
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
if (!$dtStartDate || !$dtEndDate) {
|
|
|
352 |
$startDate = date('Y-m-d');
|
|
|
353 |
$endDate = date('Y-m-d');
|
|
|
354 |
} else {
|
|
|
355 |
|
|
|
356 |
if ($dtStartDate->getTimestamp() > $dtEndDate->getTimestamp()) {
|
|
|
357 |
$startDate = date('Y-m-d');
|
|
|
358 |
$endDate = date('Y-m-d');
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
//echo ' $startDate = ' . $startDate . ' $endDate = ' . $endDate; exit;
|
|
|
364 |
|
|
|
365 |
$graph = [];
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
369 |
|
|
|
370 |
do {
|
|
|
371 |
$tempDate = $dt->format('Y-m-d');
|
|
|
372 |
$graph[ $tempDate ] = ['label' => $dt->format('d/m/Y'), 'value' => 0];
|
|
|
373 |
$dt->add(new \DateInterval('P1D'));
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
} while($endDate > $tempDate);
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
380 |
|
|
|
381 |
/*
|
|
|
382 |
select count(*) as cant, date(added_on) as date from tbl_discovery_contacts
|
|
|
383 |
where date(added_on) BETWEEN '2023-05-05' AND '2023-05-31'
|
|
|
384 |
group by date(added_on)
|
|
|
385 |
order by date ASC
|
|
|
386 |
*/
|
|
|
387 |
|
|
|
388 |
$select = $queryMapper->getSql()->select(DiscoveryContactMapper::_TABLE);
|
|
|
389 |
$select->columns([
|
|
|
390 |
'total' => new Expression('COUNT(*)'),
|
|
|
391 |
'date' => new Expression('DATE(added_on)'),
|
|
|
392 |
]);
|
|
|
393 |
$select->where->between( new Expression('DATE(added_on)') , $startDate, $endDate);
|
|
|
394 |
$select->group(new Expression('DATE(added_on)'));
|
|
|
395 |
$select->order('date ASC');
|
|
|
396 |
|
|
|
397 |
$records = $queryMapper->fetchAll($select);
|
|
|
398 |
foreach($records as $record)
|
|
|
399 |
{
|
|
|
400 |
|
|
|
401 |
$graph[ $record['date'] ][ 'value' ] = $record['total'];
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
405 |
$discoveryContactInteractionType = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($currentCompany->id);
|
|
|
406 |
if(!$discoveryContactInteractionType) {
|
|
|
407 |
$discoveryContactInteractionType = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($currentCompany->id);
|
|
|
408 |
}
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
/*
|
|
|
412 |
select count(*), user_id, date(added_on) as date from tbl_discovery_contact_interactions
|
|
|
413 |
where interaction_type_id = 1 and date(added_on) BETWEEN '2023-05-05' AND '2023-05-31'
|
|
|
414 |
group by date(added_on), user_id
|
|
|
415 |
order by date
|
|
|
416 |
*/
|
|
|
417 |
|
|
|
418 |
$table = [];
|
|
|
419 |
$select = $queryMapper->getSql()->select(DiscoveryContactInteractionMapper::_TABLE);
|
|
|
420 |
$select->columns([
|
|
|
421 |
'user_id',
|
|
|
422 |
'total' => new Expression('COUNT(*)'),
|
|
|
423 |
'date' => new Expression('DATE(added_on)'),
|
|
|
424 |
]);
|
|
|
425 |
$select->where->equalTo('interaction_type_id', $discoveryContactInteractionType->id);
|
|
|
426 |
$select->where->between( new Expression('DATE(added_on)') , $startDate, $endDate);
|
|
|
427 |
$select->group([ new Expression('DATE(added_on)'), 'user_id']);
|
|
|
428 |
$select->order('date ASC');
|
|
|
429 |
|
|
|
430 |
$records = $queryMapper->fetchAll($select);
|
|
|
431 |
foreach($records as $record)
|
|
|
432 |
{
|
|
|
433 |
$user_id = $record['user_id'];
|
|
|
434 |
|
|
|
435 |
if(!isset( $table[ $user_id ])) {
|
|
|
436 |
|
|
|
437 |
$items = [];
|
|
|
438 |
|
|
|
439 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
440 |
|
|
|
441 |
do {
|
|
|
442 |
$tempDate = $dt->format('Y-m-d');
|
|
|
443 |
$items[ $tempDate ] = ['label' => $dt->format('d/m/Y'), 'value' => 0];
|
|
|
444 |
$dt->add(new \DateInterval('P1D'));
|
|
|
445 |
|
|
|
446 |
|
|
|
447 |
} while($endDate > $tempDate);
|
|
|
448 |
|
|
|
449 |
$table[ $user_id ] = $items;
|
|
|
450 |
|
|
|
451 |
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
$table[ $user_id ][ $record['date'] ]['value'] = $record['total'];
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
$records = array_values($graph);
|
|
|
459 |
|
|
|
460 |
$spreadsheet = new Spreadsheet();
|
|
|
461 |
$spreadsheet->getProperties()->setTitle('Relevamiento de Contacto');
|
|
|
462 |
|
|
|
463 |
$spreadsheet->setActiveSheetIndex(0);
|
|
|
464 |
|
|
|
465 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
466 |
$spreadsheet->getActiveSheet()->SetCellValue('A1', 'Desde:');
|
|
|
467 |
$spreadsheet->getActiveSheet()->SetCellValue('B1', $dt->format('d/m/Y'));
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
$dt = \DateTime::createFromFormat('Y-m-d', $startDate);
|
|
|
471 |
$spreadsheet->getActiveSheet()->SetCellValue('C1', 'Hasta:');
|
|
|
472 |
$spreadsheet->getActiveSheet()->SetCellValue('D1', $dt->format('d/m/Y'));
|
|
|
473 |
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
$col = 1;
|
|
|
478 |
|
|
|
479 |
foreach($records as $record)
|
|
|
480 |
{
|
|
|
481 |
$spreadsheet->getActiveSheet()->setCellValue([$col, 3], $record['label']);
|
|
|
482 |
$spreadsheet->getActiveSheet()->setCellValue([$col, 4], $record['value']);
|
|
|
483 |
$col++;
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
$spreadsheet->getActiveSheet()->SetCellValue('A6', $this->translator->translate('LABEL_FIRST_NAME'));
|
|
|
487 |
$spreadsheet->getActiveSheet()->SetCellValue('B6', $this->translator->translate('LABEL_LAST_NAME'));
|
|
|
488 |
$spreadsheet->getActiveSheet()->SetCellValue('C6', $this->translator->translate('LABEL_EMAIL'));
|
|
|
489 |
|
|
|
490 |
|
|
|
491 |
$col = 4;
|
|
|
492 |
|
|
|
493 |
foreach($records as $record)
|
|
|
494 |
{
|
|
|
495 |
$spreadsheet->getActiveSheet()->setCellValue([$col, 6], $record['label']);
|
|
|
496 |
|
|
|
497 |
$col++;
|
|
|
498 |
}
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
$row = 7;
|
|
|
506 |
$records = $table;
|
|
|
507 |
foreach($records as $user_id => $items)
|
|
|
508 |
{
|
|
|
509 |
$user = $userMapper->fetchOne($user_id);
|
|
|
510 |
if(!$user) {
|
|
|
511 |
continue;
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
|
|
|
515 |
$spreadsheet->getActiveSheet()->SetCellValue([1, $row], $user->first_name);
|
|
|
516 |
$spreadsheet->getActiveSheet()->SetCellValue([2, $row], $user->last_name);
|
|
|
517 |
$spreadsheet->getActiveSheet()->SetCellValue([3, $row], $user->email);
|
|
|
518 |
|
|
|
519 |
|
|
|
520 |
$col = 4;
|
|
|
521 |
|
|
|
522 |
foreach($items as $item)
|
|
|
523 |
{
|
|
|
524 |
$spreadsheet->getActiveSheet()->SetCellValue([$col, $row], $item['value']);
|
|
|
525 |
$col++;
|
|
|
526 |
|
|
|
527 |
}
|
|
|
528 |
|
|
|
529 |
$row++;
|
|
|
530 |
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
$fileName = 'reporte_relevamiento_de_contact_progreso_por_dia_' . date('d-m-Y-h-i-a', time()) . '.xls';
|
|
|
534 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_relevamiento_de_contact_progreso_por_dia_' . time());
|
|
|
535 |
|
|
|
536 |
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
|
|
537 |
$writer->save($tempFilename);
|
|
|
538 |
|
|
|
539 |
$content = file_get_contents($tempFilename);
|
|
|
540 |
@unlink($tempFilename);
|
|
|
541 |
|
|
|
542 |
return new JsonModel([
|
|
|
543 |
'success' => true,
|
|
|
544 |
'data' => [
|
|
|
545 |
'content' => base64_encode($content),
|
|
|
546 |
'basename' => $fileName
|
|
|
547 |
|
|
|
548 |
]
|
|
|
549 |
]);
|
|
|
550 |
|
|
|
551 |
}
|
|
|
552 |
|
|
|
553 |
return new JsonModel([
|
|
|
554 |
'success' => false,
|
|
|
555 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
556 |
]);
|
|
|
557 |
}
|
| 15670 |
anderson |
558 |
}
|