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