Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

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