IS objednávky
  • Namespace
  • Class

Namespaces

  • Grido
    • Components
      • Columns
  • Objednavky
  • PLus
    • Orders
      • Factory
      • Repositories
        • Config
        • Documents
        • Entities
        • Lists
        • Messages
        • Order
        • Security
      • Routers

Classes

  • Grido\Components\Columns\Boolean
  • Grido\Components\Columns\BooleanExtension
  • Objednavky\AreaPresenter
  • Objednavky\BasePresenter
  • Objednavky\BranchPresenter
  • Objednavky\ConsultantPresenter
  • Objednavky\ConsultationPresenter
  • Objednavky\DepartmentPresenter
  • Objednavky\DimenzionPresenter
  • Objednavky\DirectorPresenter
  • Objednavky\DocumenttypePresenter
  • Objednavky\DownloadPresenter
  • Objednavky\EconomistPresenter
  • Objednavky\ErrorPresenter
  • Objednavky\ExpertPresenter
  • Objednavky\HomepagePresenter
  • Objednavky\InvestmentPresenter
  • Objednavky\ItemorderPresenter
  • Objednavky\JustifyPresenter
  • Objednavky\MailerPresenter
  • Objednavky\ManagerPresenter
  • Objednavky\NewsPresenter
  • Objednavky\OrderPresenter
  • Objednavky\RolePresenter
  • Objednavky\SignPresenter
  • Objednavky\TraderPresenter
  • Objednavky\UnitPresenter
  • Objednavky\UserPresenter
  • PLus\Orders\Factory\ConsultationFactory
  • PLus\Orders\Factory\DocumentFactory
  • PLus\Orders\Repositories\Config\CfgRepository
  • PLus\Orders\Repositories\Config\Mailer
  • PLus\Orders\Repositories\Config\Parameters
  • PLus\Orders\Repositories\Documents\DocumentRepository
  • PLus\Orders\Repositories\Entities\BranchRepository
  • PLus\Orders\Repositories\Entities\ChiefRepository
  • PLus\Orders\Repositories\Entities\DepartmentRepository
  • PLus\Orders\Repositories\Entities\ExpertRepository
  • PLus\Orders\Repositories\Entities\ManagerRepository
  • PLus\Orders\Repositories\Entities\TraderRepository
  • PLus\Orders\Repositories\Entities\UnitRepository
  • PLus\Orders\Repositories\Entities\UnituserRepository
  • PLus\Orders\Repositories\Entities\UserRepository
  • PLus\Orders\Repositories\Lists\AreaRepository
  • PLus\Orders\Repositories\Lists\DimenzionRepository
  • PLus\Orders\Repositories\Lists\DocumenttypeRepository
  • PLus\Orders\Repositories\Lists\EventRepository
  • PLus\Orders\Repositories\Lists\JustifyRepository
  • PLus\Orders\Repositories\Lists\OrdertypeRepository
  • PLus\Orders\Repositories\Messages\CommentRepository
  • PLus\Orders\Repositories\Messages\ConsultationRepository
  • PLus\Orders\Repositories\Messages\NewsRepository
  • PLus\Orders\Repositories\Messages\PostRepository
  • PLus\Orders\Repositories\Order\InvestmentchatRepository
  • PLus\Orders\Repositories\Order\InvestmentRepository
  • PLus\Orders\Repositories\Order\ItemareastateRepository
  • PLus\Orders\Repositories\Order\ItemorderRealizationRepository
  • PLus\Orders\Repositories\Order\ItemorderRepository
  • PLus\Orders\Repositories\Order\OrderRepository
  • PLus\Orders\Repositories\Order\RealizationRepository
  • PLus\Orders\Repositories\Order\TimelineRepository
  • PLus\Orders\Repositories\Repository
  • PLus\Orders\Repositories\Security\RoleRepository
  • PLus\Orders\Repositories\Security\UserManager
  • PLus\Orders\Routers\RouterFactory
   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  * Description of ItemorderPresenter
  15  *
  16  * @author Petr
  17  */
  18 class ItemorderPresenter extends BasePresenter {
  19     
  20     /** @var Repositories\Order\ItemorderRepository @inject */
  21     public $itemorderRepository;
  22     
  23     /** @var Repositories\Order\ItemareastateRepository @inject */
  24     public $itemareastateRepository;
  25     
  26     /** @var Repositories\Messages\CommentRepository @inject */
  27     public $commmentRepository;
  28     
  29     /** @var Repositories\Lists\AreaRepository @inject */
  30     public $areaRepository;
  31     
  32     /** @var Repositories\Lists\DimenzionRepository @inject */
  33     public $dimenzionRepository;
  34     
  35     /** @var Repositories\Order\OrderRepository @inject */
  36     public $orderRepository;
  37     
  38     /** @var Repositories\Order\InvestmentRepository @inject */
  39     public $investmentRepository;
  40     
  41     /** @var Repositories\Order\InvestmentchatRepository @inject */
  42     public $investmentchatRepository;
  43  
  44     /** @var Repositories\Order\TimelineRepository @inject */
  45     public $timelineRepository;
  46     
  47     /** @var Repositories\Entities\ExpertRepository @inject */
  48     public $expertRepository;
  49     
  50     /** @var Repositories\Entities\UserRepository @inject */
  51     public $userRepository;
  52     
  53     /** @var Repositories\Order\ItemorderRealizationRepository @inject */
  54     public $itemorderRealizationRepository;
  55     
  56     /** @var Repositories\Entities\ManagerRepository @inject */
  57     public $managerRepository;
  58     
  59     /** @var Repositories\Entities\UnituserRepository @inject */
  60     public $unituserRepository;
  61 
  62     /** @var Repositories\Entities\UnitRepository @inject */
  63     public $unitRepository;
  64     
  65     /** @var Factory\DocumentFactory @inject */
  66     public $documentFactory;
  67     
  68     /** @var Repositories\Lists\DocumenttypeRepository @inject */
  69     public $documenttypeRepository;
  70     
  71     /** @var Repositories\Documents\DocumentRepository @inject */
  72     public $documentRepository;
  73     
  74     /** @var Repositories\Messages\ConsultationRepository @inject */
  75     public $consultationRepository;
  76     
  77     /** @var Repositories\Config\Parameters @inject */
  78     public $parameters;
  79     
  80     /** @var Repositories\Config\Mailer @inject */
  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     //test pro oddeleni jestli muze videt danou polozku; to se odviji od prava k objednavce
  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     //test pro vedouciho jestli muze videt danou polozku; to se odviji od prava k objednavce a k podrizenym oddelenim
 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     //test pro konzultanta, zda muze videt danou polozku
 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     //typy uzivatelu
 133     // unit       --  smi jen na sve zaznamy
 134     // chief      --  smi na zaznamy podrizenych oddeleni
 135     // expert     --  smi jen na zaznamy, ze sve oblasti
 136     // economist  --  smi jen na schvalene zaznamy
 137     // consultant --  smi jen na zaznamy, ke kterym je pozadan o vyjadreni
 138     // trader     --  smi vsude
 139     // manager    --  smi vsude
 140     // director   --  smi vsude
 141     // admin      --  smi vsude
 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     //objednavka muze byt zamitnuta v prubehu projednavani a proto nemusi vubec dojit k zahajeni realizace
 160     //na promennou nefungoval ve view   ifset($recordofimplements), koncilo to chybou.  proto radeji test tady.
 161     //pricina je pouziti   fetch()  v dotazu  (
 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     //vracim id prideleneho resitele, ktere potom srovnavam s id prihlaseneho usera. na zaklade porovnani zobrazuju tlacitko akceptace prideleni
 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     //zjistim ze ktereho preseneteru bylo volano (Trader, Order, Manager ...)
 180     $this->template->linkback = $this->getSession()->getSection('history')->beforePresenter;
 181     }
 182     
 183     /**
 184      * 
 185      * @param type $id
 186      * nastaveni standardnich hodnot formulare sumaryTrader
 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     //kdyz se jedna o investici, pridavam dalsi template
 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      * @return \Nette\Application\UI\Form
 222      * komponenta pro vykresleni formulare Komentar
 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      * @return \Nette\Application\UI\Form
 274      * komponenta na pridani odborne oblasti k polozce
 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         //update do tabulky itemorder, ze byla prirazena oblast
 304             $this->itemorderRepository->updateById($iditemorder, array('areaflag' => 1));
 305         //pokud je to vracena objednavka (nebo je oblast dodatecne  doplnena) musim zrusit resultflag
 306         $this->itemorderRepository->updateById($iditemorder, array('resultflag' => NULL));
 307         //zaznam do timeline, ze byla prirazena oblast
 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         //zapis do item_area_state
 316         foreach ($area->area_ids as $key => $value) {
 317         //kontrola, ze takova oblast neexistuje nebo uz byla zhodnocena a zadam opakovane posouzeni
 318         $countAreaState = $this->itemareastateRepository->countAreaState($iditemorder, $value);
 319         if($countAreaState->cnt == 0) {
 320             $this->itemareastateRepository->addAreaState($iditemorder, $value, $this->getUser()->getId());
 321         }
 322         }
 323         //kontrola, zda jiz vsechny item maji pridelenou oblast
 324         //pokud ano, update tabulky order 
 325         $equal = $this->itemorderRepository->equalItemArea($itemorder->order_id);
 326         //tohle je mozna potreba predelat
 327         //odbornik by mel videt polozku hned jak je zarazena do oblasti. Jak na to??
 328         //zaroven informacni mail take hned pri zarazeni oblasti. pak neni potreba kontrolovat oblasti objednavky ale vyjit z prirazene oblasti area_id
 329         //je tady ale problem jak tu objednavku posunout k expertum jen castecne, kdyz bude mit vice polozek a ne vsechny budou mit pridelenu oblast
 330         //zatim to nebudu rozesirat  :)  28.12.2015
 331         //mel bych poslat jen na ty oblasti, ktere maji v item_area_state > isresult = NULL
 332         //ted kdyz pridam jedinou oblast (dodatecne) tak zprava poleti vsem areas !!
 333         if($equal->item <= $equal->area) {
 334         //update aby to videli experti
 335         $this->orderRepository->updateById($itemorder->order_id, array('traderdownflag' => 1, 'itemflag' => NULL));
 336         //a zapis do timeline, ze to bylo predano k odbornemu posouzeni
 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         //mail odbornikovi o pozadavku na posudek
 345         $uri = $this->getHttpRequest()->getUrl();
 346         $from = $this->parameters->getFrom();
 347         $support = $this->parameters->getSupport();
 348         //zjistuji experty  
 349         $iditems = $this->itemorderRepository->getIdItemsOrder($itemorder->order_id); //vsechny items objednavky
 350         $idarea = $this->itemorderRepository->getItemOrderAreaIdByItemId($iditems); // vsechny area vsech items
 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      * @return \Nette\Application\UI\Form
 376      * komponenta formuláře na odebrání odborné oblasti
 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     //nemam to doresene. 
 397     //co se stane, kdyz zcela vyprazdnim Area pro Item -> musim to vratit do nejakeho flagu, aby slo s objednavkou hnout
 398     //je take potreba osetrit, kdy vubec tlacitko muze byt aktivni -> urcite ne ve fazi manazer
 399     // je potreba prepracovat. jsou jeste zaznamy v item_area_state !
 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         //$this->redirect('this');
 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      * @return \Nette\Application\UI\Form
 419      * komponenta na upravu ceny polozky
 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         //$this->redirect('this');
 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      * @return \Nette\Application\UI\Form
 462      * komponenta pro vlozeni odborneho posudku
 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     //predani parametru funkce do $values
 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             //zaznam do tabulky ExpertResult
 491             $result = $form->getValues();
 492             $itemorder_id = $this->getParameter('id');       
 493         
 494         //kdyz neni investice, zapsat do tbl.ExpertResult
 495         //kdyz je investice a jedna se o investicni oblast, pak do tbl.Investmentchat
 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         //chat 1=>health, 2=>humanres, 3=>technicalsupp, 4=>construction
 507         //area 13     9        5         12
 508         $chattype = NULL;
 509         switch ($result->area_id) {
 510             case 5: //technical
 511             $chattype = 3;
 512             break;
 513             case 9: //humanres
 514             $chattype = 2;
 515             break;
 516             case 12: //construct
 517             $chattype = 4;
 518             break;
 519             case 13: //health
 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         //zaznam do item_area_state o vlozenem posudku
 543         $this->itemareastateRepository->updateState($itemorder_id, $result->area_id, $this->getUser()->getId());
 544             
 545             //zaznam do timeline posudek odbornika
 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         //kdyz jsou vsechny expertni posudky, update do tabulky itemorder do pole resultflag; 
 554         //overuju v tabulce item_area_state, zda pro danou itemorder_id existuje neposouzena oblast
 555         $countItemState = $this->itemareastateRepository->countItemState($itemorder_id);
 556         if ($countItemState->cnt == 0) {
 557         $this->itemorderRepository->updateById($itemorder_id, array('resultflag' => 1));
 558         }
 559         
 560         //a jeste kontrola zda vsechny item maji priznak v resultflag
 561         //pokud ano, potom update do tabulky order do pole itemflag; tim dojde k opetovnemu predani obchodnikovi do casti Ke schvaleni
 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         //a zapis do timeline, ze to bylo predano zpatky obchodnikovi
 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         //mail obchodnikovi
 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      * @return \Nette\Application\UI\Form
 605      * komponenta pro urceni realizatora objednavky
 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         //polozka jeste nema rozjetou realizaci, vytvoreni zaznamu o realizaci
 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         //propojeni realizatora se zaznamem o realizaci
 644         $this->itemorderRealizationRepository->assignImplementer($itemorder_realization_id, $implementer->expert_id);
 645         //update itemorder.implementerflag
 646         $this->itemorderRepository->updateById($itemorder_id, array('implementerflag' => 1));
 647         //zaznam do timeline
 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         //update na pozici realizatora
 658         $this->itemorderRealizationRepository->assignImplementer($itemorder_realization->id, $implementer->expert_id);
 659         //update itemorder_realization.lastmod
 660         $this->itemorderRealizationRepository->updateById($itemorder_realization->id, array('lastmod' => date('Y-m-d H:i:s')));
 661         //zaznam do timeline o zmene resitele
 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         //pokud $realization->realization != (0,1)
 671         $err = true;
 672         $this->flashMessage('Chyba při přidělení řešitele objednávky. Kontaktujte správce IS.', 'error');
 673         }
 674         
 675         //kdyz to neskonci chybou, poslat informacni mail resiteli
 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      * @return \Nette\Application\UI\Form
 705      * komponenta pro vlozeni zaznamu o realizaci objednavky
 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         //zaznam do tabulky itemorder_realization
 734         $this->itemorderRealizationRepository->updateById($itemorder_realization->id, 
 735             array('closed' => date('Y-m-d H:i:s'), 'description' => $recordOfImplement->description ));
 736         //zaznam o objednani ->  itemorder.orderedflag = 1
 737         $this->itemorderRepository->updateById($itemorder_id, array('orderedflag' => 1));
 738         //porovnani, pokud je objednana jen cast, potom order.realizedflag = 1
 739         //kdyz je objednano vse, potom order.realizedflag = 2
 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         //zaznam do timeline        
 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         //$this->redirect('this');
 756         
 757     } catch (\PDOException $ex) {
 758         $this->flashMessage('Chyba při uložení do DB.', 'error');
 759     }
 760     }
 761     
 762     
 763   
 764     /**
 765      * 
 766      * @return \Nette\Application\UI\Form
 767      * komponenta pro vykresleni formulare pro prideleni resitele a nebo pro akceptaci prideleni od resitele
 768      */
 769     public function createComponentAcceptImp() {
 770     $form = new UI\Form();
 771     $form->setRenderer(new BootstrapRenderer());
 772         
 773         $form->getElementPrototype()->class = 'form-horizontal';
 774     
 775     //vyvola modalni okno pro prirazeni resitele; dale v modalnim okne   createComponentAssignImplementer
 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     //akceptace prideleni; potvrzuje resitel
 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         //zaznam o akceptaci prideleni ->  itemorder.acceptedflag = 1
 799         $this->itemorderRepository->updateById($itemorder_id, array('acceptedflag' => 1));
 800         //porovnani, pokud je akceptovana jen cast, potom order.impacceptflag = 1
 801         //kdyz je akceptovano vse, potom order.impacceptflag = 2
 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      * @return \Nette\Application\UI\Form
 822      * komponenta pro pridani dokumentu k objednavce
 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      * @return \Nette\Application\UI\Form
 843      * komponenta pro vykreslení formuláře sumarizace objednávky obchodníkem
 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;  //když bude OP TRUE
 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      * @return \Nette\Application\UI\Form
 910      * prototyp formulare k vraceni objednavky
 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      * @return type
 932      * komponenta pro vykresleni formulare vraceni objednavky expertum
 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      * @return type
 946      * komponenta pro vykresleni formulare vraceni objednavky oddeleni
 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      * obsluha udalosti vraceni objednavky oddeleni nebo expertum
 959      * @param type $form
 960      * pouziva trader obdobne jako z Trader:View. Je to jen "zkratka" aby nemusel na hlavicku objednavky, ale mohl to poslat z položky
 961      * jedna se o vraceni po opakovanem behu, jiz jednou vracene a opetovne posouzene objednavky (order->returnflag = 1)
 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         //vracim expertum
 973         //zapis do order
 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         //zapis do itemorder
 983         $this->itemorderRepository->updateById($itemorder->id, array('resultflag' => NULL));
 984         //zaznam do item_area_state
 985         foreach ($areas as $key => $value) {
 986             //kontrola, ze takova oblast neexistuje nebo uz byla zhodnocena a zadam opakovane posouzeni
 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         //vracim oddeleni
 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         //zaznam do timeline
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         //zapis do comment
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         //mail o zaslani oddeleni nebo odbornikovi
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         //zjistuji oddeleni
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         //zjistuji experty  
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         //zprava
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      * @return \Nette\Application\UI\Form
1071      * tlacitko k preskoceni faze odbornych posudku primo k vedoucimu CN u vracenych objednavek
1072      * odesila si sam vedouci CN, kdyz mu vracena objednavka pristane znovu ve fazi 3 - priradit odborne oblasti
1073      * muze tedy (jinym tlacitkem) vyzadat odborne posudky, nebo timto preskocit
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         //update do tabulky order
1092         $this->orderRepository->updateById($idorder, array(
1093         'itemflag' => 1,
1094         'traderdownflag' => 1
1095         ));
1096         //zapis do timeline
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      * @return \Nette\Application\UI\Form
1116      * tovarnicka formulare pro vytvoreni prispevku chatu
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      * @return \Nette\Application\UI\Form
1178      * tlacitko pro odeslani vracene a doplnene investicni objednavky obchodnikovi
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      * @param \Nette\Forms\Controls\SubmitButton $button
1199      * odesle prispevek chatu
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      * @param \Nette\Forms\Controls\SubmitButton $button
1225      * odesle vracenou a doplnenou investicni objednavku ke schvaleni vedoucimu CN
1226      * preskakuje kroky 1-4 a nastavuje krok 5
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         //mail obchodnikovi
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      * @param \Nette\Forms\Controls\SubmitButton $button
1271      * odesle prispevek chatu
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         //vlozim zpravu do chatu
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         //zalozim pozadavek na posudek do item_area_state
1288         //kontrola, ze takova oblast neexistuje nebo uz byla zhodnocena a zadam opakovane posouzeni
1289         //chat=>area: 1=>13, 2=>9, 3=>5, 4=>12
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         //vyNULLuju order->itemflag a itemorder->resultflag
1313         $this->itemorderRepository->updateById($iditemorder, array('resultflag' => NULL));
1314         $this->orderRepository->updateById($itemorder->order_id, array('traderdownflag' => 1, 'itemflag' => NULL));
1315         //mail odbornikovi o pozadavku na posudek
1316         $uri = $this->getHttpRequest()->getUrl();
1317         $from = $this->parameters->getFrom();
1318         $support = $this->parameters->getSupport();
1319         //zjistuji experty  
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 
IS objednávky API documentation generated by ApiGen