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