Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

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