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