Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
12437 nelberth 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Authentication\Result as AuthResult;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\View\Model\ViewModel;
14
use Laminas\View\Model\JsonModel;
12443 nelberth 15
use LeadersLinked\Model\PlanningObjectivesAndGoalsObjectives;
12437 nelberth 16
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12443 nelberth 17
use LeadersLinked\Form\PlanningObjectivesAndGoalsObjectivesForm;
18
use LeadersLinked\Library\PlanningObjectivesAndGoalsObjectivesPdfOne;
19
use LeadersLinked\Library\Functions;
12437 nelberth 20
use LeadersLinked\Mapper\UserMapper;
12443 nelberth 21
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsTaskMapper;
22
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsGoalsMapper;
23
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsObjectivesMapper;
24
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsTaskMembersMapper;
25
use LeadersLinked\Mapper\CompanyMapper;
12437 nelberth 26
 
27
class HighPerformanceTeamsGroupsViewObjectivesController extends AbstractActionController
28
{
29
    /**
30
     *
31
     * @var AdapterInterface
32
     */
33
    private $adapter;
34
 
35
 
36
    /**
37
     *
38
     * @var AbstractAdapter
39
     */
40
    private $cache;
41
 
42
    /**
43
     *
44
     * @var  LoggerInterface
45
     */
46
    private $logger;
47
 
48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
54
 
55
 
56
    /**
57
     *
58
     * @param AdapterInterface $adapter
59
     * @param AbstractAdapter $cache
60
     * @param LoggerInterface $logger
61
     * @param array $config
62
     */
63
    public function __construct($adapter, $cache , $logger, $config)
64
    {
65
        $this->adapter      = $adapter;
66
        $this->cache        = $cache;
67
        $this->logger       = $logger;
68
        $this->config       = $config;
69
 
70
 
71
    }
12443 nelberth 72
 
73
 
12437 nelberth 74
 
12443 nelberth 75
 
76
    public function indexAction()
12437 nelberth 77
    {
12443 nelberth 78
 
79
 
12437 nelberth 80
        $currentUserPlugin = $this->plugin('currentUserPlugin');
81
        $currentUser = $currentUserPlugin->getUser();
82
        $currentCompany = $currentUserPlugin->getCompany();
83
 
12443 nelberth 84
 
12437 nelberth 85
        $request = $this->getRequest();
86
        if($request->isGet()) {
12443 nelberth 87
 
88
 
12437 nelberth 89
            $headers  = $request->getHeaders();
90
 
91
            $isJson = false;
92
            if($headers->has('Accept')) {
93
                $accept = $headers->get('Accept');
94
 
95
                $prioritized = $accept->getPrioritized();
96
 
97
                foreach($prioritized as $key => $value) {
98
                    $raw = trim($value->getRaw());
99
 
100
                    if(!$isJson) {
101
                        $isJson = strpos($raw, 'json');
102
                    }
103
 
104
                }
105
            }
12443 nelberth 106
 
107
            if($isJson) {
108
 
109
 
110
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
111
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/edit');
112
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/delete');
113
                $allowObjective = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals');
114
                $allowObjectiveReport = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/report');
115
                $allowObjectiveReportAll = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/reportall');
116
 
117
 
12437 nelberth 118
 
12443 nelberth 119
                $search = $this->params()->fromQuery('search', []);
120
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
121
 
122
 
123
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
124
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
125
                $order =  $this->params()->fromQuery('order', []);
126
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
127
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
128
 
129
                $fields =  ['title', 'date'];
130
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
131
 
132
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
133
                    $order_direction = 'ASC';
134
                }
12437 nelberth 135
 
12443 nelberth 136
 
137
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
138
 
139
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
140
 
141
                $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
142
 
143
                $paginator = $planningObjectivesAndGoalsObjectivesMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $currentCompany->id);
144
 
145
                $items = [];
146
 
147
                $records = $paginator->getCurrentItems();
148
 
149
                foreach($records as $record)
150
                {
151
 
152
 
153
 
154
                    $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($record->id);
155
                    $costObjective=0;
156
                    $indicatorObjective=0;
157
                    $contador=0;
158
                    $countRecordsGoals = count($recordsGoals);
159
                    if($countRecordsGoals>0){
160
                        foreach($recordsGoals as $record2)
161
                        {
162
                            $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
163
                            $costGoals=0;
164
                            $indicatorGoals=0;
165
                            $countRecordsTask = count($recordsTask);
166
                            if($countRecordsTask>0){
167
                                foreach($recordsTask as $record3){
168
                                    $indicatorGoals=$indicatorGoals+$record3->indicator;
169
                                    $costGoals=$costGoals+$record3->cost;
170
                                }
171
                                $indicatorObjective=$indicatorObjective+($indicatorGoals/$countRecordsTask);
172
                                $costObjective=$costObjective+$costGoals;
173
                                $contador++;
174
                            }
175
                        }
176
                        if($indicatorObjective==0){
177
                            $indicatorObjective=(-1);
178
                        }else{
179
                            $indicatorObjective=round($indicatorObjective/$contador,2);
180
 
181
                        }
182
                    }else{
183
                        $indicatorObjective=(-2);
184
                    }
185
 
186
                    $date='';
187
                    if($record->date!=NULL){
188
                        $dt = \DateTime::createFromFormat('Y-m-d', $record->date);
189
                        $date =  $dt->format('d/m/Y');
190
                    }
191
                    $item = [
192
                        'title' => $record->title,
193
                        'description' => $record->description,
194
                        'date'=> $date,
195
                        'cost'=>$costObjective,
196
                        'progress'=>$indicatorObjective,
197
                        'status'=> $record->status,
198
                        'link_report_all'> $allowObjectiveReportAll ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/reportall') : '',
199
                        'actions' => [
200
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/edit', ['id' => $record->uuid]) : '',
201
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/delete', ['id' => $record->uuid]) : '',
202
                            'link_objective' => $allowObjective ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals', ['objective_id' => $record->uuid]) : '',
203
                            'link_objective_report' => $allowObjectiveReport ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/report', ['id' => $record->uuid]) : '',
204
 
205
                        ]
206
 
207
                    ];
208
 
209
 
210
                    array_push($items, $item);
211
 
212
                }
213
 
214
                $recordsObjectivesModule = $planningObjectivesAndGoalsObjectivesMapper->fetchAll($currentCompany->id);
215
                $costModule=0;
216
                $indicatorModule=0;
217
                $contadorTotalModule=0;
218
                $countRecordsObjectives = count($recordsObjectivesModule);
219
                if($countRecordsObjectives>0){
220
 
221
                    foreach($recordsObjectivesModule as $record)
222
                    {
223
 
224
                        $recordsGoalsModule = $planningObjectivesAndGoalsGoalsMapper->fetchAll($record->id);
225
                        $costObjectiveModule=0;
226
                        $indicatorObjectiveModule=0;
227
                        $contadorModule=0;
228
                        $countRecordsGoalsModule = count($recordsGoalsModule);
229
                        if($countRecordsGoalsModule>0){
230
 
231
                            foreach($recordsGoalsModule as $record2)
232
                            {
233
 
234
                                $recordsTaskModule = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
235
                                $costGoalsModule=0;
236
                                $indicatorGoalsModule=0;
237
                                $countRecordsTaskModule = count($recordsTaskModule);
238
                                if($countRecordsTaskModule>0){
239
                                    foreach($recordsTaskModule as $record3){
240
 
241
                                        $indicatorGoalsModule=$indicatorGoalsModule+$record3->indicator;
242
                                        $costGoalsModule=$costGoalsModule+$record3->cost;
243
                                    }
244
                                    $indicatorObjectiveModule=$indicatorObjectiveModule+($indicatorGoalsModule/$countRecordsTaskModule);
245
                                    $costModule=$costModule+$costGoalsModule;
246
                                    $contadorModule++;
247
                                }
248
                            }
249
                            if($indicatorObjectiveModule>0){
250
                                $indicatorModule=$indicatorModule+($indicatorObjectiveModule/$contadorModule);
251
                                $contadorTotalModule++;
252
                            }
253
                        }
254
 
255
                    }
256
                    if($indicatorModule==0){
257
                        $indicatorModule=(-5);
258
                    }else{
259
                        $indicatorModule=round($indicatorModule/$contadorTotalModule,2);
260
                    }
261
                }else{
262
                    $indicatorModule=(-3);
263
                }
264
 
265
 
266
                return new JsonModel([
267
                    'success' => true,
268
                    'data' => [
269
                        'items' => $items,
270
                        'total' => $paginator->getTotalItemCount(),
271
                        'module'=>[
272
                            'costModule' => '$'.$costModule,
273
                            'indicatorModule'=>$indicatorModule
274
                        ]
275
                    ]
276
                ]);
277
 
278
            } else  {
279
                $formAdd = new PlanningObjectivesAndGoalsObjectivesForm();
280
                $this->layout()->setTemplate('layout/layout-backend');
281
                $viewModel = new ViewModel();
12445 nelberth 282
                $viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-objectives/index.phtml');
12443 nelberth 283
                $viewModel->setVariables([
284
                    'formAdd' => $formAdd,
285
                ]);
12437 nelberth 286
                return $viewModel ;
287
            }
12443 nelberth 288
        } else {
289
            return new JsonModel([
290
                'success' => false,
291
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
292
            ]);
293
        }
294
    }
295
    public function addAction()
296
    {
297
      $currentUserPlugin = $this->plugin('currentUserPlugin');
298
        $currentUser = $currentUserPlugin->getUser();
299
        $currentCompany = $currentUserPlugin->getCompany();
300
 
301
        $request = $this->getRequest();
302
        if($request->isPost()) {
303
            $form = new  PlanningObjectivesAndGoalsObjectivesForm();
304
            $dataPost = $request->getPost()->toArray();
305
 
306
            $form->setData($dataPost);
307
 
308
            if($form->isValid()) {
309
                $dataPost = (array) $form->getData();
310
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsObjectives::STATUS_INACTIVE;
311
                $dataPost['company_id']=$currentCompany->id;
312
 
313
                $hydrator = new ObjectPropertyHydrator();
314
                $planningObjectivesAndGoalsObjectives = new PlanningObjectivesAndGoalsObjectives();
315
                $hydrator->hydrate($dataPost, $planningObjectivesAndGoalsObjectives);
316
 
317
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
318
                $result = $planningObjectivesAndGoalsObjectivesMapper->insert($planningObjectivesAndGoalsObjectives);
319
 
320
                if($result) {
321
                    $this->logger->info('Se agrego el objetivo ' . $planningObjectivesAndGoalsObjectives->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
322
 
323
                    $data = [
324
                        'success'   => true,
325
                        'data'   => 'LABEL_RECORD_ADDED'
326
                    ];
327
                } else {
328
                    $data = [
329
                        'success'   => false,
330
                        'data'      => $planningObjectivesAndGoalsObjectivesMapper->getError()
331
                    ];
332
 
333
                }
334
 
335
                return new JsonModel($data);
336
 
337
            } else {
338
                $messages = [];
339
                $form_messages = (array) $form->getMessages();
340
                foreach($form_messages  as $fieldname => $field_messages)
341
                {
342
 
343
                    $messages[$fieldname] = array_values($field_messages);
344
                }
345
 
346
                return new JsonModel([
347
                    'success'   => false,
348
                    'data'   => $messages
349
                ]);
12437 nelberth 350
            }
351
 
12443 nelberth 352
        } else {
353
            $data = [
354
                'success' => false,
355
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
356
            ];
357
 
358
            return new JsonModel($data);
359
        }
360
 
361
        return new JsonModel($data);
362
 
363
 
364
    }
365
 
366
 
367
 
368
     public function editAction(){
369
 
370
        $currentUserPlugin = $this->plugin('currentUserPlugin');
371
        $currentUser = $currentUserPlugin->getUser();
372
        $currentCompany = $currentUserPlugin->getCompany();
373
        $request = $this->getRequest();
374
        $uuid = $this->params()->fromRoute('id');
375
 
376
 
377
        if(!$uuid) {
378
            $data = [
379
                'success'   => false,
380
                'data'   => 'ERROR_INVALID_PARAMETER'
381
            ];
382
 
383
            return new JsonModel($data);
384
        }
385
 
386
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
387
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid);
388
 
389
        if (!$objectives) {
390
            $data = [
391
                'success' => false,
392
                'data' => 'ERROR_RECORD_NOT_FOUND'
393
            ];
394
 
395
            return new JsonModel($data);
396
        }
397
 
398
        if ($objectives->company_id != $currentCompany->id) {
399
            return new JsonModel([
400
                'success' => false,
401
                'data' => 'ERROR_UNAUTHORIZED'
12437 nelberth 402
            ]);
12443 nelberth 403
        }
404
 
405
        if($request->isPost()) {
406
            $form = new  PlanningObjectivesAndGoalsObjectivesForm();
407
            $dataPost = $request->getPost()->toArray();
408
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsObjectives::STATUS_INACTIVE;
409
            $form->setData($dataPost);
12437 nelberth 410
 
12443 nelberth 411
            if($form->isValid()) {
412
                $dataPost = (array) $form->getData();
413
 
414
                $hydrator = new ObjectPropertyHydrator();
415
                $hydrator->hydrate($dataPost, $objectives);
416
                $result = $planningObjectivesAndGoalsObjectivesMapper->update($objectives);
417
 
418
                if($result) {
419
                    $this->logger->info('Se actualizo el objetivo ' . $objectives->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
420
 
421
                    $data = [
422
                        'success' => true,
423
                        'data' => 'LABEL_RECORD_UPDATED'
424
                    ];
425
                } else {
426
                    $data = [
427
                        'success'   => false,
428
                        'data'      => $planningObjectivesAndGoalsObjectivesMapper->getError()
429
                    ];
430
                }
431
 
432
                return new JsonModel($data);
433
 
434
            } else {
435
                $messages = [];
436
                $form_messages = (array) $form->getMessages();
437
                foreach($form_messages  as $fieldname => $field_messages)
438
                {
439
                    $messages[$fieldname] = array_values($field_messages);
440
                }
441
 
442
                return new JsonModel([
443
                    'success'   => false,
444
                    'data'   => $messages
445
                ]);
446
            }
447
        }else if ($request->isGet()) {
448
            $hydrator = new ObjectPropertyHydrator();
12437 nelberth 449
 
12443 nelberth 450
            $data = [
451
                'success' => true,
452
                'data' => $hydrator->extract($objectives)
453
            ];
454
 
455
            return new JsonModel($data);
12437 nelberth 456
        } else {
12443 nelberth 457
            $data = [
458
                'success' => false,
459
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
460
            ];
461
 
462
            return new JsonModel($data);
463
        }
464
 
465
        return new JsonModel($data);
466
 
467
    }
468
 
469
 
470
 
471
 
472
    public function deleteAction(){
473
        $currentUserPlugin = $this->plugin('currentUserPlugin');
474
        $currentCompany = $currentUserPlugin->getCompany();
475
        $currentUser = $currentUserPlugin->getUser();
476
 
477
        $request = $this->getRequest();
478
        $uuid = $this->params()->fromRoute('id');
479
 
480
 
481
        if (!$uuid) {
482
            $data = [
483
                'success' => false,
484
                'data' => 'ERROR_INVALID_PARAMETER'
485
            ];
486
 
487
            return new JsonModel($data);
488
        }
489
 
490
 
491
 
492
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
493
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid);
494
 
495
        if (!$objectives) {
496
            $data = [
497
                'success' => false,
498
                'data' => 'ERROR_RECORD_NOT_FOUND'
499
            ];
500
 
501
            return new JsonModel($data);
502
        }
503
 
504
        if ($objectives->company_id != $currentCompany->id) {
12437 nelberth 505
            return new JsonModel([
506
                'success' => false,
12443 nelberth 507
                'data' => 'ERROR_UNAUTHORIZED'
508
            ]);
509
        }
510
 
511
        if ($request->isPost()) {
512
 
513
 
514
            $result = $planningObjectivesAndGoalsObjectivesMapper->delete($objectives->id);
515
            if ($result) {
516
                $this->logger->info('Se borro el objetivo con el titulo ' . $objectives->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
517
 
518
                $data = [
519
                    'success' => true,
520
                    'data' => 'LABEL_RECORD_DELETED'
521
                ];
522
            } else {
523
 
524
                $data = [
525
                    'success' => false,
526
                    'data' => $planningObjectivesAndGoalsObjectivesMapper->getError()
527
                ];
528
 
529
                return new JsonModel($data);
530
            }
531
        } else {
532
            $data = [
533
                'success' => false,
12437 nelberth 534
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
12443 nelberth 535
            ];
536
 
537
            return new JsonModel($data);
12437 nelberth 538
        }
12443 nelberth 539
 
540
        return new JsonModel($data);
541
    }
12437 nelberth 542
 
12443 nelberth 543
 
544
 
545
    public function reportAction() {
546
        $currentUserPlugin = $this->plugin('currentUserPlugin');
547
        $currentUser = $currentUserPlugin->getUser();
548
        $currentCompany = $currentUserPlugin->getCompany();
549
 
550
        $request = $this->getRequest();
551
        $uuid = $this->params()->fromRoute('id');
552
 
553
 
554
        if (!$uuid) {
555
            $data = [
556
                'success' => false,
557
                'data' => 'ERROR_INVALID_PARAMETER'
558
            ];
559
 
560
            return new JsonModel($data);
561
        }
562
 
563
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
564
        $recordsObjectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid);
12437 nelberth 565
 
12443 nelberth 566
        if (!$recordsObjectives) {
567
            $data = [
568
                'success' => false,
569
                'data' => 'Objetivo ERROR_RECORD_NOT_FOUND'
570
            ];
571
 
572
            return new JsonModel($data);
573
        }
574
 
575
        if ($recordsObjectives->company_id != $currentCompany->id) {
576
            return new JsonModel([
577
                'success' => false,
578
                'data' => 'ERROR_UNAUTHORIZED'
579
            ]);
580
        }
581
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
582
        $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($recordsObjectives->id);
583
 
584
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
585
        $userMapper = UserMapper::getInstance($this->adapter);
586
        $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
587
 
588
            foreach($recordsGoals as $record2){
589
 
590
                $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
591
 
592
 
593
                foreach($recordsTask as $record3){
594
                    $recordsTaskMembers =  $PlanningObjectivesAndGoalsTaskMemberMapper->fetchAll($record3->id);
595
                    $usersName=[];
596
                    foreach($recordsTaskMembers as $record4){
597
                        $datosUser = $userMapper->fetchOne($record4->user_id);
598
                        $usersName[$record4->id]=$datosUser->first_name.' '.$datosUser->last_name;
599
                    }
600
                    $record3->who=$usersName;
601
                }
602
 
603
 
604
 
605
 
606
                $record2->task = $recordsTask;
607
            }
608
           $items=[
609
            'objetives' => [
610
                'title'=>$recordsObjectives->title,
611
                'description' =>$recordsObjectives->description,
612
                'date'=>$recordsObjectives->date,
613
                'status'=>$recordsObjectives->status,
614
                'goals'=>$recordsGoals
615
            ]
616
            ];
617
 
618
 
619
 
620
 
621
 
622
        if ($request->isGet()) {
623
 
624
 
625
            return $this->renderPdf($currentCompany,$items);
626
        } else {
627
            $data = [
628
                'success' => false,
629
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
630
            ];
631
 
632
            return new JsonModel($data);
633
        }
634
 
635
        return new JsonModel($data);
12437 nelberth 636
    }
12443 nelberth 637
    public function reportallAction() {
638
        $currentUserPlugin = $this->plugin('currentUserPlugin');
639
        $currentUser = $currentUserPlugin->getUser();
640
        $currentCompany = $currentUserPlugin->getCompany();
12437 nelberth 641
 
12443 nelberth 642
        $request = $this->getRequest();
643
 
644
 
645
 
646
 
647
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
648
        $recordsObjectives = $planningObjectivesAndGoalsObjectivesMapper->fetchAll($currentCompany->id);
649
 
650
        if (!$recordsObjectives) {
651
            $data = [
652
                'success' => false,
653
                'data' => 'Objetivo ERROR_RECORD_NOT_FOUND'
654
            ];
655
 
656
            return new JsonModel($data);
657
        }
658
 
659
 
660
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
661
 
662
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
663
        $items;
664
        $contador=0;
665
        foreach($recordsObjectives as $record){
666
 
667
            if ($record->company_id != $currentCompany->id) {
668
                return new JsonModel([
669
                    'success' => false,
670
                    'data' => 'ERROR_UNAUTHORIZED'
671
                ]);
672
            }
673
            $userMapper = UserMapper::getInstance($this->adapter);
674
            $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
675
            $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($record->id);
676
 
677
                foreach($recordsGoals as $record2){
678
 
679
                    $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
680
 
681
 
682
                    foreach($recordsTask as $record3){
683
                        $recordsTaskMembers =  $PlanningObjectivesAndGoalsTaskMemberMapper->fetchAll($record3->id);
684
                        $usersName=[];
685
                        foreach($recordsTaskMembers as $record4){
686
                            $datosUser = $userMapper->fetchOne($record4->user_id);
687
                            $usersName[$record4->id]=$datosUser->first_name.' '.$datosUser->last_name;
688
                        }
689
                        $record3->who=$usersName;
690
                    }
691
 
692
                    $record2->task = $recordsTask;
693
                }
694
         /*   $item=[
695
                $contador => [
696
                    'title'=>$record->title,
697
                    'description' =>$record->description,
698
                    'date'=>$record->date,
699
                    'status'=>$record->status,
700
                    'goals'=>$recordsGoals
701
                ]
702
            ];
703
            array_push($items, $item);
704
            $contador++;*/
705
        $record->goals=$recordsGoals;
706
        }
707
 
708
 
709
 
710
        if ($request->isGet()) {
711
 
712
 
713
            return $this->renderPdf($currentCompany,$recordsObjectives,2);
714
        } else {
715
            $data = [
716
                'success' => false,
717
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
718
            ];
719
 
720
            return new JsonModel($data);
721
        }
722
 
723
        return new JsonModel($data);
724
    }
725
    public function matrizAction() {
726
        $currentUserPlugin = $this->plugin('currentUserPlugin');
727
        $currentUser = $currentUserPlugin->getUser();
728
        $currentCompany = $currentUserPlugin->getCompany();
729
 
730
        $request = $this->getRequest();
731
 
732
 
733
 
734
 
735
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
736
        $recordsObjectives = $planningObjectivesAndGoalsObjectivesMapper->fetchAll($currentCompany->id);
737
 
738
        if (!$recordsObjectives) {
739
            $data = [
740
                'success' => false,
741
                'data' => 'Objetivo ERROR_RECORD_NOT_FOUND'
742
            ];
743
 
744
            return new JsonModel($data);
745
        }
746
 
747
 
748
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
749
 
750
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
751
        $items;
752
        $contador=0;
753
        foreach($recordsObjectives as $record){
754
 
755
            if ($record->company_id != $currentCompany->id) {
756
                return new JsonModel([
757
                    'success' => false,
758
                    'data' => 'ERROR_UNAUTHORIZED'
759
                ]);
760
            }
761
            $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($record->id);
762
 
763
                foreach($recordsGoals as $record2){
764
 
765
                    $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
766
                    $record2->task = $recordsTask;
767
                }
768
         /*   $item=[
769
                $contador => [
770
                    'title'=>$record->title,
771
                    'description' =>$record->description,
772
                    'date'=>$record->date,
773
                    'status'=>$record->status,
774
                    'goals'=>$recordsGoals
775
                ]
776
            ];
777
            array_push($items, $item);
778
            $contador++;*/
779
        $record->goals=$recordsGoals;
780
        }
781
 
782
 
783
 
784
        if ($request->isGet()) {
785
 
786
 
787
            return $this->renderPdf($currentCompany,$recordsObjectives,3);
788
        } else {
789
            $data = [
790
                'success' => false,
791
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
792
            ];
793
 
794
            return new JsonModel($data);
795
        }
796
 
797
        return new JsonModel($data);
798
    }
799
 
800
 
801
 
802
    public function renderPDF($currentCompany,$items,$switch=1) {
803
 
804
        $pdf = new PlanningObjectivesAndGoalsObjectivesPdfOne();
805
 
806
        $pdf->header = '';
807
        $pdf->footer = '';
808
        if ($currentCompany) {
809
            //get company Data
810
            $companyMapper = CompanyMapper::getInstance($this->adapter);
811
            $company = $companyMapper->fetchOne($currentCompany->id);
812
 
813
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
814
 
815
            $pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
816
            $pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
817
        }
818
 
819
        $pdf->SetMargins(10,200,10);
820
        $pdf->SetAutoPageBreak(true,40);
821
        $pdf->AliasNbPages();
822
 
823
 
824
            if($switch==3){
825
                $pdf->borderTableMatriz('Planificacion - Objetivos y metas',$items);
826
            }else if($switch==2){
827
                $pdf->borderTableAll('Planificacion - Objetivos y metas',$items);
828
 
829
            }else{
830
                $pdf->borderTable('Planificacion - Objetivos y metas',$items);
831
 
832
            }
833
 
834
 
835
 
836
 
837
        return $pdf->Output();
838
    }
12437 nelberth 839
}