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