1 <?php
2
3 namespace Objednavky;
4
5 use Nette\Application\UI;
6 use Nette\Utils\Html;
7 use Nette\Database\Table\Selection;
8 use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
9 use PLus\Orders\Repositories;
10 use PLus\Orders\Factory;
11
12
13 14 15 16 17
18 class ItemorderPresenter extends BasePresenter {
19
20
21 public $itemorderRepository;
22
23
24 public $itemareastateRepository;
25
26
27 public $commmentRepository;
28
29
30 public $areaRepository;
31
32
33 public $dimenzionRepository;
34
35
36 public $orderRepository;
37
38
39 public $investmentRepository;
40
41
42 public $investmentchatRepository;
43
44
45 public $timelineRepository;
46
47
48 public $expertRepository;
49
50
51 public $userRepository;
52
53
54 public $itemorderRealizationRepository;
55
56
57 public $managerRepository;
58
59
60 public $unituserRepository;
61
62
63 public $unitRepository;
64
65
66 public $documentFactory;
67
68
69 public $documenttypeRepository;
70
71
72 public $documentRepository;
73
74
75 public $consultationRepository;
76
77
78 public $parameters;
79
80
81 public $mailerCfg;
82
83
84
85
86 public function renderView($id) {
87
88 $item = $this->itemorderRepository->findByIdWithDimenzion($id);
89 $user = $this->getUser();
90
91 if ($item === false) {
92 $this->flashMessage('Položka č. '. $id .' nebyla dohledána.', 'error');
93 $this->redirect('Homepage:default');
94 }
95
96
97 if ($user->getIdentity()->isunit == 1) {
98 $orderbyid = $this->orderRepository->findOrderIdUnitById($item->order_id,$user->getId(),$user->getId());
99 if ($orderbyid === false) {
100 $this->flashMessage('Nemáte právo přístupu k položce č. '.$id, 'error');
101 $this->redirect('Homepage:default');
102 }
103 }
104
105
106
107 if ($user->getIdentity()->ischief == 1 && !$user->isInRole('sa') && !$user->isInRole('admin') && !$user->isInRole('trader')
108 && !$user->isInRole('manager') && !$user->isInRole('expert') && !$user->isInRole('economist') && !$user->isInRole('director')
109 && !$user->isInRole('consultant')) {
110
111 $unit = $this->unitRepository->getUnits($user->getId());
112 $ids = $this->unituserRepository->getIds($unit);
113 $orderbyid = $this->orderRepository->findOrderIdUnitById($item->order_id,$this->getUser()->getId(),$ids);
114 if ($orderbyid === false) {
115 $this->flashMessage('Nemáte právo přístupu k položce č. '.$id, 'error');
116 $this->redirect('Homepage:default');
117 }
118 }
119
120
121
122 if ($user->isInRole('consultant')) {
123 $ids = $this->consultationRepository->findConsultIds($user->getId());
124 $orderbyid = $this->orderRepository->findOrderIdForConsultant($item->order_id, $ids);
125 if ($orderbyid === false) {
126 $this->flashMessage('Nemáte právo přístupu k položce č. '.$id, 'error');
127 $this->redirect('Consultant:watch');
128 }
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 $this->template->data = $item;
145 $this->template->itemareas = $this->itemorderRepository->getItemOrderAreaById($item->id);
146 $this->template->userareas = $this->userRepository->getUserAreaById($user->getId());
147 $this->template->useridareas = $this->areaRepository->findAreaById($user->getId());
148 $this->template->expertresults = $this->expertRepository->getExpertResults($item->id);
149 $this->template->comments = $this->itemorderRepository->getItemOrderCommentById($item->id);
150 $this->template->itemorderhead = $this->itemorderRepository->getItemOrderHeadById($item->order_id);
151 $this->template->comments = $this->commmentRepository->getCommentByItemorderId($item->id);
152 $this->template->orderhead = $this->orderRepository->findById($item->order_id);
153 $this->template->manapproved = $this->managerRepository->getManagerApproved($item->order_id);
154 $this->template->implementer = $this->itemorderRealizationRepository->getAssignImplementerByItemorderId($item->id);
155 $this->template->maxsizedoc = $this->parameters->formatBytes($this->parameters->getMaxSizeUpload());
156 $this->template->notresultarea = $this->itemareastateRepository->findAreaNotResult($item->id);
157
158
159
160
161
162 $recordofimplements = $this->itemorderRealizationRepository->getRecordOfImplementation($item->id);
163 if ($recordofimplements) {
164 $this->template->recordofimplements = $recordofimplements;
165 }
166 else {
167 $this->template->recordofimplements = null;
168 }
169
170
171 $implementerid = $this->itemorderRealizationRepository->getAssignImplementerId($item->id);
172 if ($implementerid) {
173 $this->template->implementerid = $implementerid;
174 }
175 else {
176 $this->template->implementerid = null;
177 }
178
179
180 $this->template->linkback = $this->getSession()->getSection('history')->beforePresenter;
181 }
182
183 184 185 186 187
188 public function actionView($id) {
189
190 $item = $this->itemorderRepository->findByIdWithDimenzion($id);
191
192 $this['summaryTrader']->setDefaults(array(
193 'name' => $item->name,
194 'sum_number' => $item->sum_number,
195 'dimenzion' => $item->dimenzion_id,
196 'sum_priceitem' => $item->sum_priceitem,
197 'isplan' => $item->isplan,
198 'yearplan' => $item->yearplan? $item->yearplan : date("Y"),
199 'note' => $item->note
200 ));
201
202
203 if ($this->orderRepository->isInvestment($item->order_id)->isinvestment == 1) {
204 $this->template->investment = $this->investmentRepository->getByOrderId($item->order_id);
205
206 $this->template->heatltbadge = $this->investmentchatRepository->getCountBadge($item->order_id, 1);
207 $this->template->humanresbadge = $this->investmentchatRepository->getCountBadge($item->order_id, 2);
208 $this->template->technicalsuppbadge = $this->investmentchatRepository->getCountBadge($item->order_id, 3);
209 $this->template->constructionbadge = $this->investmentchatRepository->getCountBadge($item->order_id, 4);
210
211 $this->template->healthchat = $this->investmentchatRepository->findChatPostsByOrderId($item->order_id, 1);
212 $this->template->humanreschat = $this->investmentchatRepository->findChatPostsByOrderId($item->order_id, 2);
213 $this->template->technicalsuppchat = $this->investmentchatRepository->findChatPostsByOrderId($item->order_id, 3);
214 $this->template->constructionchat = $this->investmentchatRepository->findChatPostsByOrderId($item->order_id, 4);
215 }
216 }
217
218
219 220 221 222 223
224 public function createComponentComment() {
225
226 $form = new UI\Form();
227 $form->setRenderer(new BootstrapRenderer());
228
229 $form->getElementPrototype()->class = 'form-horizontal';
230
231 $form->addText('description', '')
232 ->setAttribute('class', 'form-control input-sm')
233 ->setAttribute('type', 'comment');
234
235 $form->addSubmit('send')
236 ->setAttribute('class', 'btn btn-warning btn-sm')
237 ->setAttribute('id', 'sendComment')
238 ->getControlPrototype()
239 ->setName('button')
240 ->setText('Odeslat komentář');
241
242 $form->onSuccess[] = $this->commentSubmitted;
243
244 return $form;
245 }
246
247 public function commentSubmitted($form) {
248
249 try {
250
251 $iditemorder = $this->getParameter('id');
252 $comment = $form->getValues();
253 if (mb_strlen(trim($comment->description)) > 0) {
254 $c = new \Nette\Utils\ArrayHash;
255 $c->itemorder_id = $iditemorder;
256 $c->user_id = $this->getUser()->getId();
257 $c->description = $comment->description;
258 $c->created = date('Y-m-d H:i:s');
259 $this->commmentRepository->insertData($c);
260
261 $this->redirect('this');
262 }
263 else {
264 $this->flashMessage('Prázdný komentář nelze uložit.', 'error');
265 }
266 } catch (\PDOException $e) {
267 $this->flashMessage("Chyba při uložení komentáře. ".$e->getMessage(), 'error');
268 }
269 }
270
271 272 273 274 275
276 public function createComponentAddArea() {
277
278 $form = new UI\Form();
279 $form->setRenderer(new BootstrapRenderer());
280
281 $form->getElementPrototype()->class = 'form-horizontal';
282
283 $form->addMultiSelect('area_ids', 'Oblast:', $this->areaRepository->getPairDataNotIn($this->getParameter('id')),15)
284 ->setAttribute('class', 'form-control');
285
286 $form->addSubmit('saving', 'Zařadit')
287 ->setAttribute('class', 'btn btn-primary');
288
289 $form->onSuccess[] = $this->addAreaSubmitted;
290
291 return $form;
292 }
293
294 public function addAreaSubmitted($form) {
295
296 try {
297 $iditemorder = $this->getParameter('id');
298 $itemorder = $this->itemorderRepository->findById($iditemorder);
299 $area = $form->getValues();
300 foreach ($area->area_ids as $key => $value) {
301 $this->itemorderRepository->assignArea($value, $iditemorder);
302 }
303
304 $this->itemorderRepository->updateById($iditemorder, array('areaflag' => 1));
305
306 $this->itemorderRepository->updateById($iditemorder, array('resultflag' => NULL));
307
308 $t = new \Nette\Utils\ArrayHash;
309 $t->order_id = $itemorder->order_id;
310 $t->user_id = $this->getUser()->getId();
311 $t->event_id = 14;
312 $t->created = date('Y-m-d H:i:s');
313 $this->timelineRepository->insertData($t);
314
315
316 foreach ($area->area_ids as $key => $value) {
317
318 $countAreaState = $this->itemareastateRepository->countAreaState($iditemorder, $value);
319 if($countAreaState->cnt == 0) {
320 $this->itemareastateRepository->addAreaState($iditemorder, $value, $this->getUser()->getId());
321 }
322 }
323
324
325 $equal = $this->itemorderRepository->equalItemArea($itemorder->order_id);
326
327
328
329
330
331
332
333 if($equal->item <= $equal->area) {
334
335 $this->orderRepository->updateById($itemorder->order_id, array('traderdownflag' => 1, 'itemflag' => NULL));
336
337 $t2 = new \Nette\Utils\ArrayHash;
338 $t2->order_id = $itemorder->order_id;
339 $t2->user_id = $this->getUser()->getId();
340 $t2->event_id = 5;
341 $t2->created = date('Y-m-d H:i:s');
342 $this->timelineRepository->insertData($t2);
343
344
345 $uri = $this->getHttpRequest()->getUrl();
346 $from = $this->parameters->getFrom();
347 $support = $this->parameters->getSupport();
348
349 $iditems = $this->itemorderRepository->getIdItemsOrder($itemorder->order_id);
350 $idarea = $this->itemorderRepository->getItemOrderAreaIdByItemId($iditems);
351 $to = $this->userRepository->getExpertEmail($idarea);
352 $subject = 'Objednávka k odbornému posouzení';
353 $params = array(
354 'order_id' => $itemorder->order_id,
355 'contact' => $support,
356 'url' => $uri->hostUrl.'/expert&execution=view&id='.$itemorder->order_id
357 );
358 $template = __DIR__ . '/../templates/Mailer/emailToExpert.latte';
359 $image = __DIR__ . '/../../www/img/logo32x32.gif';
360 $mailer = $this->mailerCfg->getMailConfig();
361
362 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
363 }
364
365 $this->flashMessage('Byla přiřazena odborná oblast.', 'success');
366 $this->redirect('Trader:in');
367
368 } catch (\PDOException $e) {
369 $this->flashMessage("Chyba při uložení do DB. ".$e->getMessage(), 'error');
370 }
371 }
372
373 374 375 376 377
378 public function createComponentRemoveArea() {
379
380 $form = new UI\Form();
381 $form->setRenderer(new BootstrapRenderer());
382 $iditemorder = $this->getParameter('id');
383
384 $form->getElementPrototype()->class = 'form-horizontal';
385 $form->addSelect('area_id', 'Oblast:', $this->areaRepository->findPairAreaToItemById($iditemorder))
386 ->setAttribute('class', 'form-control');
387
388 $form->addSubmit('delete', 'Odebrat')
389 ->setAttribute('class', 'btn btn-primary');
390
391 $form->onSuccess[] = array($this,'removeAreaSubmitted');
392
393 return $form;
394 }
395
396
397
398
399
400 public function removeAreaSubmitted($form, $values) {
401
402 try {
403 $itemorder_id = $this->getParameter('id');
404 $area_id = $values->area_id;
405 $this->itemorderRepository->removeAssignedArea($area_id, $itemorder_id);
406
407 $this->flashMessage('Odborná oblast byla odebrána.', 'success');
408
409
410 } catch (\PDOException $e) {
411 $this->flashMessage("Chyba při uložení do DB. ".$e->getMessage() , 'error');
412 }
413
414 }
415
416 417 418 419 420
421 public function createComponentUpdatePriceItem(){
422
423 $form = new UI\Form();
424 $form->setRenderer(new BootstrapRenderer());
425
426 $form->getElementPrototype()->class = 'form-horizontal';
427 $form->addText('iprice', 'Cena:')
428 ->addRule(UI\Form::FLOAT, 'Očekávaná hodnota musí být číslo')
429 ->setAttribute('placeholder', 'Vložte celkovou cenu za všechny kusy položky')
430 ->setAttribute('class', 'form-control');
431
432 $form->addSubmit('send', 'Upravit cenu')
433 ->setAttribute('class', 'btn btn-primary');
434
435 $form->onSuccess[] = $this->updatePriceItemSubmitted;
436
437 return $form;
438 }
439
440 public function updatePriceItemSubmitted($form) {
441 try {
442 $iditemorder = $this->getParameter('id');
443 $price = $form->getValues()->iprice;
444
445 if($price != 0)
446 $this->itemorderRepository->updatePriceItem($iditemorder, $price);
447 else {
448 $this->flashMessage('Nelze ukládat nulovou hodnotu.', 'info');
449 }
450
451
452
453 } catch (\PDOException $e) {
454 $this->flashMessage("Chyba při uložení do DB. ".$e->getMessage(), 'error');
455 }
456 }
457
458
459 460 461 462 463
464 public function createComponentExpertResult($area_id) {
465 $form = new UI\Form();
466 $form->setRenderer(new BootstrapRenderer());
467
468 $form->getElementPrototype()->class = 'form-horizontal';
469
470 $form->addTextArea('description', 'Posudek:', NULL, 10)
471 ->setRequired('Zadejte prosím odůvodnění')
472 ->setAttribute('class', 'form-control')
473 ->setAttribute('type', 'modal');
474
475
476 $form->addHidden('area_id', $area_id)
477 ->setAttribute('id', 'inputAreaId');
478
479 $form->addSubmit('saving', 'Uložit a zpět')
480 ->setAttribute('class', 'btn btn-primary');
481
482 $form->onSuccess[] = $this->expertResultSubmitted;
483
484 return $form;
485 }
486
487 public function expertResultSubmitted($form) {
488
489 try {
490
491 $result = $form->getValues();
492 $itemorder_id = $this->getParameter('id');
493
494
495
496 $isinvestment = $this->itemorderRepository->isInvestment($itemorder_id)->isinvestment;
497 $investmentarea = $this->areaRepository->getInvestmentArea();
498
499 $is_iarea = FALSE;
500 foreach ($investmentarea as $iarea) {
501 if ( $result->area_id == $iarea) {
502 $is_iarea = TRUE;
503 }
504 }
505 if ( $isinvestment == 1 && $is_iarea ) {
506
507
508 $chattype = NULL;
509 switch ($result->area_id) {
510 case 5:
511 $chattype = 3;
512 break;
513 case 9:
514 $chattype = 2;
515 break;
516 case 12:
517 $chattype = 4;
518 break;
519 case 13:
520 $chattype = 1;
521 break;
522 }
523
524 $this->investmentchatRepository->insertData(array(
525 'text' => $result->description,
526 'created' => date('Y-m-d H:i:s'),
527 'investment_id' => $this->itemorderRepository->getInvestmentId($itemorder_id)->id,
528 'user_id' => $this->getUser()->getId(),
529 'ichattype_id' => $chattype
530 ));
531 }
532 else {
533 $this->expertRepository->insertData(array(
534 'description' => $result->description,
535 'lastmod' => date('Y-m-d H:i:s'),
536 'itemorder_id' => $itemorder_id,
537 'user_id' => $this->getUser()->getId(),
538 'area_id' => $result->area_id
539 ));
540 }
541
542
543 $this->itemareastateRepository->updateState($itemorder_id, $result->area_id, $this->getUser()->getId());
544
545
546 $t = new \Nette\Utils\ArrayHash;
547 $t->order_id = $this->itemorderRepository->findById($itemorder_id)->order_id;
548 $t->user_id = $this->getUser()->getId();
549 $t->event_id = 6;
550 $t->created = date('Y-m-d H:i:s');
551 $this->timelineRepository->insertData($t);
552
553
554
555 $countItemState = $this->itemareastateRepository->countItemState($itemorder_id);
556 if ($countItemState->cnt == 0) {
557 $this->itemorderRepository->updateById($itemorder_id, array('resultflag' => 1));
558 }
559
560
561
562 $order_id = $this->itemorderRepository->findById($itemorder_id)->order_id;
563 $countresultflag = $this->itemorderRepository->getCountItemResultflag($order_id);
564 $countiteminorder = $this->itemorderRepository->getCountItemInOrder($order_id);
565 if ($countiteminorder->item == $countresultflag->resultflag) {
566 $this->orderRepository->updateById($order_id, array('itemflag' => 1,'returnflag' => NULL));
567
568
569 $this->timelineRepository->insertData(array(
570 'order_id' => $order_id,
571 'user_id' => $this->getUser()->getId(),
572 'event_id' => 3,
573 'created' => date('Y-m-d H:i:s')
574 ));
575
576
577 $uri = $this->getHttpRequest()->getUrl();
578 $from = $this->parameters->getFrom();
579 $support = $this->parameters->getSupport();
580 $to = $this->userRepository->getTraderEmail();
581 $subject = 'Objednávka k posouzení';
582 $params = array(
583 'order_id' => $order_id,
584 'contact' => $support,
585 'url' => $uri->hostUrl.'/trader&execution=view&id='.$order_id
586 );
587 $template = __DIR__ . '/../templates/Mailer/emailToTraderValidate.latte';
588 $image = __DIR__ . '/../../www/img/logo32x32.gif';
589 $mailer = $this->mailerCfg->getMailConfig();
590
591 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
592 }
593
594 $this->flashMessage("Odborný posudek k objednávce č. $order_id byl uložen.", 'success');
595 $this->redirect('Expert:validate');
596
597 } catch (\PDOException $e) {
598 $this->flashMessage("Chyba při uložení do DB. ".$e->getMessage(), 'error');
599 }
600 }
601
602 603 604 605 606
607 protected function createComponentAssignImplementer() {
608
609 $form = new UI\Form();
610 $form->setRenderer(new BootstrapRenderer());
611
612 $form->getElementPrototype()->class = 'form-horizontal';
613
614 $iditemorder = $this->getParameter('id');
615 $itemorder = $this->itemorderRepository->findById($iditemorder);
616 $area_id = $this->itemorderRepository->getItemOrderAreaIdByItemId($itemorder->order_id);
617
618 $form->addSelect('expert_id', 'Realizátor:', $this->userRepository->getUserByArea($area_id))
619 ->setAttribute('class', 'form-control');
620
621 $form->addSubmit('saving', 'Uložit')
622 ->setAttribute('class', 'btn btn-primary');
623
624
625 $form->onSuccess[] = $this->assignImplementerSubmitted;
626
627 return $form;
628 }
629
630 public function assignImplementerSubmitted($form) {
631
632 try {
633 $err = false;
634 $implementer = $form->getValues();
635 $itemorder_id = $this->getParameter('id');
636 $itemorder = $this->itemorderRepository->findById($itemorder_id);
637 $realization = $this->itemorderRepository->getItemRealizationExists($itemorder_id);
638 if( $realization->realization == 0) {
639
640 $newrealization = $this->itemorderRealizationRepository
641 ->insertData(array('itemorder_id' => $itemorder_id, 'created' => date('Y-m-d H:i:s'), 'lastmod' => date('Y-m-d H:i:s')));
642 $itemorder_realization_id = $newrealization->id;
643
644 $this->itemorderRealizationRepository->assignImplementer($itemorder_realization_id, $implementer->expert_id);
645
646 $this->itemorderRepository->updateById($itemorder_id, array('implementerflag' => 1));
647
648 $t = new \Nette\Utils\ArrayHash;
649 $t->order_id = $itemorder->order_id;
650 $t->user_id = $this->getUser()->getId();
651 $t->event_id = 13;
652 $t->created = date('Y-m-d H:i:s');
653 $this->timelineRepository->insertData($t);
654 }
655 elseif ($realization->realization == 1) {
656 $itemorder_realization = $this->itemorderRealizationRepository->findById($itemorder_id);
657
658 $this->itemorderRealizationRepository->assignImplementer($itemorder_realization->id, $implementer->expert_id);
659
660 $this->itemorderRealizationRepository->updateById($itemorder_realization->id, array('lastmod' => date('Y-m-d H:i:s')));
661
662 $t = new \Nette\Utils\ArrayHash;
663 $t->order_id = $itemorder->order_id;
664 $t->user_id = $this->getUser()->getId();
665 $t->event_id = 16;
666 $t->created = date('Y-m-d H:i:s');
667 $this->timelineRepository->insertData($t);
668 }
669 else {
670
671 $err = true;
672 $this->flashMessage('Chyba při přidělení řešitele objednávky. Kontaktujte správce IS.', 'error');
673 }
674
675
676 if ($err == FALSE) {
677 $uri = $this->getHttpRequest()->getUrl();
678 $from = $this->parameters->getFrom();
679 $support = $this->parameters->getSupport();
680 $to = $this->userRepository->getImplementerEmail($implementer->expert_id);
681 $subject = 'Objednávka k realizaci';
682 $params = array(
683 'order_id' => $itemorder->order_id,
684 'contact' => $support,
685 'url' => $uri->hostUrl.'/expert&execution=view&id='.$itemorder->order_id
686 );
687 $template = __DIR__ . '/../templates/Mailer/emailToImplementer.latte';
688 $image = __DIR__ . '/../../www/img/logo32x32.gif';
689 $mailer = $this->mailerCfg->getMailConfig();
690
691 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
692 }
693
694 $this->redirect('this');
695
696 } catch (\PDOException $e) {
697 $this->flashMessage('Chyba při uložení do DB.', 'error');
698 }
699 }
700
701
702 703 704 705 706
707 public function createComponentExpertRecordOfImplement() {
708
709 $form = new UI\Form();
710 $form->setRenderer(new BootstrapRenderer());
711
712 $form->getElementPrototype()->class = 'form-horizontal';
713
714 $form->addTextArea('description', 'Záznam:', NULL, 10)
715 ->setRequired('Zadejte informace o realizaci')
716 ->setAttribute('class', 'form-control');
717
718 $form->addSubmit('saving', 'Uložit a zpět')
719 ->setAttribute('class', 'btn btn-primary');
720
721 $form->onSuccess[] = $this->expertRecordOfImplementSubmitted;
722
723 return $form;
724 }
725
726 public function expertRecordOfImplementSubmitted($form) {
727
728 try {
729 $recordOfImplement = $form->getValues();
730 $itemorder_id = $this->getParameter('id');
731 $itemorder = $this->itemorderRepository->findById($itemorder_id);
732 $itemorder_realization = $this->itemorderRealizationRepository->findById($itemorder_id);
733
734 $this->itemorderRealizationRepository->updateById($itemorder_realization->id,
735 array('closed' => date('Y-m-d H:i:s'), 'description' => $recordOfImplement->description ));
736
737 $this->itemorderRepository->updateById($itemorder_id, array('orderedflag' => 1));
738
739
740 $equal = $this->itemorderRepository->equalItemOrdered($itemorder->order_id);
741 if ($equal->item > $equal->ordered) {
742 $this->orderRepository->updateById($itemorder->order_id, array('realizedflag' => 1));
743 }
744 elseif ($equal->item == $equal->ordered) {
745 $this->orderRepository->updateById($itemorder->order_id, array('realizedflag' => 2));
746 }
747
748 $this->timelineRepository->insertData(array(
749 'order_id' => $itemorder->order_id,
750 'user_id' => $this->getUser()->getId(),
751 'event_id' => 17,
752 'created' => date('Y-m-d H:i:s')
753 ));
754
755
756
757 } catch (\PDOException $ex) {
758 $this->flashMessage('Chyba při uložení do DB.', 'error');
759 }
760 }
761
762
763
764 765 766 767 768
769 public function createComponentAcceptImp() {
770 $form = new UI\Form();
771 $form->setRenderer(new BootstrapRenderer());
772
773 $form->getElementPrototype()->class = 'form-horizontal';
774
775
776 $form->addSubmit('assign')
777 ->setAttribute('class','btn btn-primary')
778 ->setAttribute('data-target', '#implementerModal')
779 ->setAttribute('data-toggle', 'modal')
780 ->getControlPrototype()
781 ->setName('a')
782 ->add(Html::el('i')->class('fa fa-users fa-fw'))
783 ->add(Html::el('span', 'Přiřadit řešitele'));
784
785
786 $form->addSubmit('accept', 'Přijmout')
787 ->setAttribute('class', 'btn btn-primary');
788
789 $form->onSuccess[] = $this->acceptSubmitted;
790
791 return $form;
792 }
793
794 public function acceptSubmitted($form) {
795 try {
796 $itemorder_id = $this->getParameter('id');
797 $itemorder = $this->itemorderRepository->findById($itemorder_id);
798
799 $this->itemorderRepository->updateById($itemorder_id, array('acceptedflag' => 1));
800
801
802 $equal = $this->itemorderRepository->equalItemAccepted($itemorder->order_id);
803 if ($equal->item > $equal->accepted) {
804 $this->orderRepository->updateById($itemorder->order_id, array('impacceptflag' => 1));
805 }
806 elseif ($equal->item == $equal->accepted) {
807 $this->orderRepository->updateById($itemorder->order_id, array('impacceptflag' => 2));
808 }
809
810 $this->flashMessage('Akceptace přidělení realizace byla uložena do DB.', 'success');
811 $this->redirect('this');
812
813 } catch (\PDOException $ex) {
814 $this->flashMessage('Chyba při uložení do DB.', 'error');
815 }
816 }
817
818
819 820 821 822 823
824 public function createComponentAddDocument() {
825
826 try {
827 $iduser = $this->getUser()->getId();
828 $idorder = $this->getParameter('id');
829
830 $form = $this->documentFactory->createAddDocument($idorder,$iduser);
831 $this->flashMessage('Soubor byl uložen.', 'success');
832
833 return $form;
834
835 } catch (\PDOException $e) {
836 $this->flashMessage("Soubor se nepodařilo uložit! ".$e->getMessage(), "error");
837 }
838 }
839
840 841 842 843 844
845 public function createComponentSummaryTrader() {
846
847 $form = new UI\Form();
848 $form->setRenderer(new BootstrapRenderer());
849
850 $form->getElementPrototype()->class = 'form-horizontal';
851 $form->addText('name', 'Název položky:')
852 ->setAttribute('class', 'form-control');
853 $form->addText('sum_number', 'Množství k nákupu:')
854 ->setRequired('Hodnota musí být zadána')
855 ->addRule(UI\Form::INTEGER, 'Hodnota musí být celé číslo')
856 ->setAttribute('class', 'form-control')
857 ->setAttribute('id', 'summarynumber');
858 $form->addSelect('dimenzion', 'Jednotka:', $this->dimenzionRepository->getPairData())
859 ->setAttribute('class', 'form-control3')
860 ->setAttribute('id', 'dimenzion');
861 $form->addText('sum_priceitem', 'Celková cena:')
862 ->setRequired('Hodnota musí být zadána')
863 ->addRule(UI\Form::FLOAT, 'Hodnota musí být číslo')
864 ->setAttribute('class', 'form-control');
865 $form->addCheckbox('isplan');
866 $form->addText('yearplan', 'pro rok:')
867 ->setAttribute('class', 'form-control')
868 ->addConditionOn($form['isplan'], UI\Form::EQUAL, TRUE)
869 ->setRequired('Je vyžadována hodnota roku Obchodního plánu')
870 ->addRule(UI\Form::PATTERN, 'Hodnota musí být ve formátu RRRR', '\d{4}');
871 $form->addTextArea('note', 'Poznámka:', NULL, 4)
872 ->setAttribute('placeholder', 'Můžete vložit doplňující informace, např. upřesnění typu zboží/služby.')
873 ->setAttribute('class', 'form-control');
874
875 $form->addSubmit('send', 'Odeslat')
876 ->setAttribute('class', 'btn btn-primary');
877
878 $form->onSuccess[] = array($this, 'summaryTraderSubmitted');
879
880 return $form;
881 }
882
883 public function summaryTraderSubmitted($form, $values) {
884
885 try {
886
887 $itemorder_id = $this->getParameter('id');
888 $data = new \Nette\Utils\ArrayHash;
889 $data->sum_number = $values->sum_number;
890 $data->sum_priceitem = $values->sum_priceitem;
891 $data->isplan = $values->isplan? $values->isplan : NULL;
892 $data->yearplan = $values->isplan? $values->yearplan : NULL;
893 $data->note = $values->note? $values->note : NULL;
894 $data->dimenzion_id = $values->dimenzion;
895 $this->itemorderRepository->updateById($itemorder_id, $data);
896
897 $this->flashMessage('Shrnutí obchodníka bylo uloženo do DB.', 'success');
898 $this->redirect('Trader:view',$itemorder_id);
899
900 } catch (\PDOException $e) {
901 $this->flashMessage("Chyba při uložení do DB. ".$e->getMessage(), 'error');
902 }
903 }
904
905
906
907 908 909 910 911
912 function createTraderBack() {
913
914 $form = new UI\Form();
915 $form->setRenderer(new BootstrapRenderer());
916
917 $form->getElementPrototype()->class = 'form-horizontal';
918
919 $form->addTextArea('message', 'Komentář:', NULL, 4)
920 ->setRequired('Upřesněte požadavek na doplnění.')
921 ->setAttribute('class', 'form-control');
922
923 $form->addSubmit('back', 'Odeslat')
924 ->setAttribute('class', 'btn btn-primary');
925
926 return $form;
927 }
928
929 930 931 932 933
934 public function createComponentTraderBackToExpert() {
935
936 $form = $this->createTraderBack();
937 $form->addHidden('back_id', 1);
938 $form->onSuccess[] = $this->traderBackSubmitted;
939
940 return $form;
941 }
942
943 944 945 946 947
948 public function createComponentTraderBackToDepartment() {
949
950 $form = $this->createTraderBack();
951 $form->addHidden('back_id', 0);
952 $form->onSuccess[] = $this->traderBackSubmitted;
953
954 return $form;
955 }
956
957 958 959 960 961 962
963 public function traderBackSubmitted($form) {
964 try {
965 $result = $form->getValues();
966 $itemorder = $this->itemorderRepository->findById($this->getParameter('id'));
967 $areas = $this->itemorderRepository->getItemOrderAreaIdByItemId($itemorder->id);
968 $idorder = $itemorder->order_id;
969
970
971 if ($result->back_id == '1') {
972
973
974 $this->orderRepository->updateById($idorder, array(
975 'returnflag' => 1,
976 'traderdownflag' => 1,
977 'completeflag' => NULL,
978 'managerflag' => NULL,
979 'traderupflag' => NULL,
980 'itemflag' => NULL
981 ));
982
983 $this->itemorderRepository->updateById($itemorder->id, array('resultflag' => NULL));
984
985 foreach ($areas as $key => $value) {
986
987 $countAreaState = $this->itemareastateRepository->countAreaState($itemorder->id, $value);
988 if($countAreaState->cnt == 0) {
989 $this->itemareastateRepository->addAreaState($itemorder->id, $value, $this->getUser()->getId());
990 }
991 }
992 }
993 elseif ($result->back_id == '0') {
994
995 $this->orderRepository->updateById($idorder, array(
996 'returnflag' => 1,
997 'completeflag' => NULL,
998 'managerflag' => NULL,
999 'traderupflag' => NULL,
1000 'traderdownflag' => NULL,
1001 'itemflag' => NULL,
1002 'chiefflag' => NULL,
1003 'departmentflag' => NULL
1004 ));
1005 }
1006
1007 $this->timelineRepository->insertData(array(
1008 'order_id' => $idorder,
1009 'user_id' => $this->getUser()->getId(),
1010 'event_id' => 9,
1011 'created' => date('Y-m-d H:i:s')
1012 ));
1013
1014
1015 if (mb_strlen(trim($result->message)) > 0) {
1016 $this->commmentRepository->insertData(array(
1017 'itemorder_id' => $this->getParameter('id'),
1018 'user_id' => $this->getUser()->getId(),
1019 'description' => $result->message,
1020 'created' => date('Y-m-d H:i:s')
1021 ));
1022 }
1023
1024 $uri = $this->getHttpRequest()->getUrl();
1025 $from = $this->parameters->getFrom();
1026 $support = $this->parameters->getSupport();
1027 $item = $this->orderRepository->findById($idorder);
1028 $subject = 'Objednávka vrácená k doplnění';
1029 if ($result->back_id == '0') {
1030
1031 $to = $this->userRepository->getUnitEmail($item->user_id);
1032 $params = array(
1033 'order_id' => $idorder,
1034 'contact' => $support,
1035 'url' => $uri->hostUrl.'/order&execution=view&id='.$idorder
1036 );
1037 $template = __DIR__ . '/../templates/Mailer/emailToUnitBack.latte';
1038 }
1039 else {
1040
1041 $iditems = $this->itemorderRepository->getIdItemsOrder($item->id);
1042 $idarea = $this->itemorderRepository->getItemOrderAreaIdByItemId($iditems);
1043 $to = $this->userRepository->getExpertEmail($idarea);
1044 $params = array(
1045 'order_id' => $idorder,
1046 'contact' => $support,
1047 'url' => $uri->hostUrl.'/expert&execution=view&id='.$idorder
1048 );
1049 $template = __DIR__ . '/../templates/Mailer/emailToExpertBack.latte';
1050 }
1051
1052 $image = __DIR__ . '/../../www/img/logo32x32.gif';
1053 $mailer = $this->mailerCfg->getMailConfig();
1054
1055 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
1056
1057
1058 $text = ($result->back_id == 0)? 'požadujícímu oddělení' : 'k odbornémmu posouzení';
1059 $this->flashMessage('Objednávka č. '.$idorder.' byla vrácena '.$text.'.', 'success');
1060 $this->redirect('Trader:in');
1061
1062 } catch (\PDOException $ex) {
1063 $this->flashMessage("Chyba při uložení do DB. ".$ex->getMessage(), 'error');
1064 }
1065 }
1066
1067
1068 1069 1070 1071 1072 1073 1074
1075 public function createComponentJumpToTraderResult() {
1076
1077 $form = new UI\Form();
1078 $form->setRenderer(new BootstrapRenderer());
1079
1080 $form->addSubmit('send','Odeslat přímo ke stanovisku vedoucího CN');
1081
1082 $form->onSuccess[] = $this->jumpTraderResultSubmitted;
1083 return $form;
1084 }
1085
1086 public function jumpTraderResultSubmitted($form) {
1087 try {
1088 $itemorder = $this->itemorderRepository->findById($this->getParameter('id'));
1089 $idorder = $itemorder->order_id;
1090 $user = $this->getUser();
1091
1092 $this->orderRepository->updateById($idorder, array(
1093 'itemflag' => 1,
1094 'traderdownflag' => 1
1095 ));
1096
1097 $this->timelineRepository->insertData(array(
1098 'order_id' => $idorder,
1099 'user_id' => $user->getId(),
1100 'event_id' => 18,
1101 'created' => date('Y-m-d H:i:s')
1102 ));
1103
1104 $this->flashMessage('Původní odborné posudky byly akceptovány a objednávka je připravena k posouzení obchodníkem.', 'success');
1105 $this->redirect('this');
1106
1107 } catch (\PDOException $ex) {
1108 $this->flashMessage("Chyba při uložení do DB. ".$ex->getMessage(), 'error');
1109 }
1110 }
1111
1112
1113 1114 1115 1116 1117
1118 public function createInvestmentChat() {
1119
1120 $form = new UI\Form();
1121 $form->setRenderer(new BootstrapRenderer());
1122 $form->getElementPrototype()->class = 'chatmetro-form';
1123 $form->addTextArea('message', '', NULL, 4)
1124 ->setRequired();
1125 $form->addSubmit('sendChief', 'Odeslat příspěvek')
1126 ->setAttribute('class', 'btn btn-info')
1127 ->setAttribute('id', 'tooltipCh')
1128 ->setAttribute('data-placement', 'right')
1129 ->setAttribute('data-original-title', 'Odešle příspěvek do diskuze ve zvolené odborné oblasti.')
1130 ->onClick[] = array($this, 'ichatChiefSubmitted');
1131
1132 $form->addSubmit('sendToTrader', 'Odeslat obchodníkovi')
1133 ->setAttribute('class', 'btn btn-warning')
1134 ->setAttribute('id', 'tooltipTT')
1135 ->setAttribute('data-placement', 'right')
1136 ->setAttribute('data-original-title', 'Po doplnění všech požadovaných informací v jednotlivých chatech odešlete tímto tlačítkem vedoucímu centrálního nákupu.')
1137 ->onClick[] = array($this, 'ichatToTraderSubmitted');
1138
1139 $form->addSubmit('sendFromTrader', 'Vyžádat posudek')
1140 ->setAttribute('class', 'btn btn-info')
1141 ->setAttribute('id', 'tooltipT')
1142 ->setAttribute('data-placement', 'right')
1143 ->setAttribute('data-original-title', 'Umožňuje vyžádat opakovaný posudek jen pro zvolenou odbornou oblast.')
1144 ->onClick[] = array($this, 'ichatFromTraderSubmitted');
1145
1146 return $form;
1147 }
1148
1149
1150 public function createComponentHealthChat() {
1151 $form = $this->createInvestmentChat();
1152 $form->addHidden('ichattype_id', 1);
1153 return $form;
1154 }
1155
1156 public function createComponentHumanChat() {
1157 $form = $this->createInvestmentChat();
1158 $form->addHidden('ichattype_id', 2);
1159 return $form;
1160 }
1161
1162 public function createComponentTechnicalChat() {
1163 $form = $this->createInvestmentChat();
1164 $form->addHidden('ichattype_id', 3);
1165 return $form;
1166 }
1167
1168 public function createComponentConstructionChat() {
1169 $form = $this->createInvestmentChat();
1170 $form->addHidden('ichattype_id', 4);
1171 return $form;
1172 }
1173
1174
1175 1176 1177 1178 1179
1180 public function createComponentSendInvestmentToTrader() {
1181 $form = new UI\Form();
1182 $form->setRenderer(new BootstrapRenderer());
1183 $form->getElementPrototype()->class = 'form-horizontal margin';
1184
1185 $form->addSubmit('sendToTrader', 'Odeslat obchodníkovi')
1186 ->setAttribute('class', 'btn btn-warning btn-lg btn-block')
1187 ->setAttribute('id', 'tooltipTT')
1188 ->setAttribute('data-placement', 'top')
1189 ->setAttribute('data-original-title', 'Po doplnění všech požadovaných informací v jednotlivých chatech odešlete tímto tlačítkem vedoucímu centrálního nákupu.')
1190 ->onClick[] = array($this, 'ichatToTraderSubmitted');
1191
1192 return $form;
1193 }
1194
1195
1196 1197 1198 1199 1200
1201 public function ichatChiefSubmitted(\Nette\Forms\Controls\SubmitButton $button) {
1202 try {
1203 $values = $button->form->getValues();
1204 $iditemorder = $this->getParameter('id');
1205 $this->investmentchatRepository->insertData(array(
1206 'text' => $values->message,
1207 'created' => date('Y-m-d H:i:s'),
1208 'investment_id' => $this->itemorderRepository->getInvestmentId($iditemorder)->id,
1209 'user_id' => $this->getUser()->getId(),
1210 'ichattype_id' => $values->ichattype_id
1211 ));
1212 $this->flashMessage("Příspěvek do diskuze byl uložen. Pokud byly doplněny všechny požadované informace, "
1213 . "odešlete k posouzení vedoucímu centrálního nákupu tlačítkem 'Odeslat obchodníkovi'.", 'info');
1214 $this->redirect('this');
1215
1216 } catch (\PDOException $ex) {
1217 $this->flashMessage("Chyba při uložení do DB. ".$ex->getMessage(), 'error');
1218 }
1219
1220 }
1221
1222 1223 1224 1225 1226 1227 1228
1229 public function ichatToTraderSubmitted(\Nette\Forms\Controls\SubmitButton $button) {
1230 try {
1231 $iditemorder = $this->getParameter('id');
1232 $itemorder = $this->itemorderRepository->findById($iditemorder);
1233 $this->orderRepository->updateById($itemorder->order_id, array(
1234 'departmentflag' => 1,
1235 'chiefflag' => 1,
1236 'traderdownflag' => 1,
1237 'itemflag' => 1,
1238 'returnflag' => NULL
1239 ));
1240
1241
1242 $uri = $this->getHttpRequest()->getUrl();
1243 $from = $this->parameters->getFrom();
1244 $support = $this->parameters->getSupport();
1245 $to = $this->userRepository->getTraderEmail();
1246 $subject = 'Objednávka k posouzení';
1247 $params = array(
1248 'order_id' => $itemorder->order_id,
1249 'contact' => $support,
1250 'url' => $uri->hostUrl.'/trader&execution=view&id='.$itemorder->order_id
1251 );
1252 $template = __DIR__ . '/../templates/Mailer/emailToTraderValidate.latte';
1253 $image = __DIR__ . '/../../www/img/logo32x32.gif';
1254 $mailer = $this->mailerCfg->getMailConfig();
1255
1256 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
1257
1258
1259 $this->flashMessage("Objednávka č. $itemorder->order_id byla zaslána k posouzení vedoucímu CN.", 'success');
1260 $this->redirect('this');
1261
1262
1263 } catch (\PDOException $ex) {
1264 $this->flashMessage("Chyba při uložení do DB. ".$ex->getMessage(), 'error');
1265 }
1266 }
1267
1268 1269 1270 1271 1272
1273 public function ichatFromTraderSubmitted(\Nette\Forms\Controls\SubmitButton $button) {
1274 try {
1275 $values = $button->form->getValues();
1276 $iditemorder = $this->getParameter('id');
1277 $itemorder = $this->itemorderRepository->findById($iditemorder);
1278
1279 $this->investmentchatRepository->insertData(array(
1280 'text' => $values->message,
1281 'created' => date('Y-m-d H:i:s'),
1282 'investment_id' => $this->itemorderRepository->getInvestmentId($iditemorder)->id,
1283 'user_id' => $this->getUser()->getId(),
1284 'ichattype_id' => $values->ichattype_id,
1285 'inverted' => 1
1286 ));
1287
1288
1289
1290 switch ($values->ichattype_id) {
1291 case 1:
1292 $area_id = 13;
1293 $area_name = 'Zdravotní pojištovny';
1294 break;
1295 case 2:
1296 $area_id = 9;
1297 $area_name = 'Personální vybavení';
1298 break;
1299 case 3:
1300 $area_id = 5;
1301 $area_name = 'Zdravotnická technika';
1302 break;
1303 case 4:
1304 $area_id = 12;
1305 $area_name = 'Stavební úpravy';
1306 break;
1307 }
1308 $countAreaState = $this->itemareastateRepository->countAreaState($iditemorder, $area_id);
1309 if($countAreaState->cnt == 0) {
1310 $this->itemareastateRepository->addAreaState($iditemorder, $area_id, $this->getUser()->getId());
1311 }
1312
1313 $this->itemorderRepository->updateById($iditemorder, array('resultflag' => NULL));
1314 $this->orderRepository->updateById($itemorder->order_id, array('traderdownflag' => 1, 'itemflag' => NULL));
1315
1316 $uri = $this->getHttpRequest()->getUrl();
1317 $from = $this->parameters->getFrom();
1318 $support = $this->parameters->getSupport();
1319
1320 $to = $this->userRepository->getExpertEmail($area_id);
1321 $subject = 'Objednávka k odbornému posouzení';
1322 $params = array(
1323 'order_id' => $itemorder->order_id,
1324 'contact' => $support,
1325 'url' => $uri->hostUrl.'/expert&execution=view&id='.$itemorder->order_id
1326 );
1327 $template = __DIR__ . '/../templates/Mailer/emailToExpert.latte';
1328 $image = __DIR__ . '/../../www/img/logo32x32.gif';
1329 $mailer = $this->mailerCfg->getMailConfig();
1330
1331 MailerPresenter::sendMail($from, $to, $subject, $params, $template, $image, $mailer);
1332
1333 $this->flashMessage("Příspěvek byl uložen mezi posudky v části $area_name. Informační email odborníkovi byl odeslán.", 'info');
1334 $this->redirect('this');
1335
1336 } catch (\PDOException $ex) {
1337 $this->flashMessage("Chyba při uložení do DB. ".$ex->getMessage(), 'error');
1338 }
1339
1340 }
1341 }
1342