/**
  * @param $listingID
  * @param $withTime
  * @return ListingResult
  */
 private function getListingByID($listingID, $withTime = false)
 {
     $result = $this->listingsFacade->getListingByID($listingID, $withTime);
     if ($result === null or !$this->authorizator->isAllowed($this->user->getIdentity(), $result->getListing())) {
         $this->flashMessage('Výčetka nebyla nalezena.', 'warning');
         $this->redirect('Listing:overview');
     }
     return $result;
 }
 public function render()
 {
     $template = $this->getTemplate();
     $template->setFile(__DIR__ . '/annualPdfGeneration.latte');
     $annualListings = $this->listingsFacade->getListingsYears($this->user);
     krsort($annualListings);
     $template->listingsData = $annualListings;
     $template->render();
 }
 public function processDeleteListing(\Nette\Forms\Controls\SubmitButton $button)
 {
     try {
         $this->listingsFacade->removeListing($this->listing);
     } catch (DBALException $e) {
         $this->flashMessage('Výčetka nemohla být odstraněna. Zkuste akci opakovat později.', 'warning');
         $this->redirect('this');
     }
     $this->onRemoveSuccess($this->listing->getYear(), $this->listing->getMonth());
 }
 public function showTableCaption($destination = null, array $params = [])
 {
     if ($destination !== null) {
         $this['description']->setAsClickable($destination, $params);
     }
     $listingData = $this->listingsFacade->getWorkedDaysAndTime($this->listing->getId());
     $this->workedDays = $listingData['worked_days'];
     $this->totalWorkedHours = new \InvoiceTime((int) $listingData['total_worked_hours_in_sec']);
     $this->isTableCaptionVisible = true;
 }
 public function processForm(Form $form, $values)
 {
     try {
         $newListing = $this->listingsFacade->establishListingCopy($this->listing, true, (array) $values);
     } catch (\Exception $e) {
         $this->flashMessage('Kopie výčetky nemohla být založena. Zkuste prosím akci
              opakovat později.', 'warning');
         $this->redirect('this');
     }
     $this->onListingCopySuccess($newListing);
 }
 public function render()
 {
     $template = $this->getTemplate();
     $template->setFile(__DIR__ . '/templates/template.latte');
     if ($this->listingsQuery->getMonth() !== null) {
         $this->template->date = new \DateTime($this->listingsQuery->getYear() . '-' . $this->listingsQuery->getMonth() . '-01');
     }
     $this->listings = $this->prepareListings($this->listingsFacade->fetchListings($this->listingsQuery)->toArray(AbstractQuery::HYDRATE_SCALAR));
     $template->heading = $this->heading;
     $template->numberOfListings = isset($this->listings) ? Arrays::count_recursive($this->listings, 1) : 0;
     $template->listings = $this->listings;
     $template->render();
 }
 public function processForm(Form $form, $values)
 {
     if ($this->listing === null) {
         $this->listing = new Listing($values['year'], $values['month'], $this->owner);
     }
     $this->listing->description = $values['description'];
     $this->listing->hourlyWage = $values['hourlyWage'];
     $this->listingFacade->saveListing($this->listing);
     $this->presenter->flashMessage('Výčetka pro ' . TimeUtils::getMonthName($values['month']) . ' ' . $values['year'] . ' byla uložena.', 'success');
     if (isset($this->presenter->backlink)) {
         $this->presenter->restoreRequest($this->presenter->backlink);
     }
     $this->presenter->redirect('Listing:overview', array('month' => $values['month'], 'year' => $values['year']));
 }
 public function processMassItemsChange(Form $form, $values)
 {
     $daysToChange = $form->getHttpData(Form::DATA_TEXT, 'items[]');
     if (empty($daysToChange)) {
         $this->flashMessage('Označte řádky, které chcete změnit.', 'warning');
         if ($this->presenter->isAjax()) {
             $this->redrawControl('flashMessage');
             return;
         } else {
             $this->redirect('this');
         }
     }
     try {
         $workedHours = new WorkedHours($values['workStart'], $values['workEnd'], $values['lunch'], $values['otherHours']);
         if ($values['newListing'] === true) {
             $newListing = $this->listingsFacade->baseListingOn($this->listing, $workedHours, $daysToChange);
         } else {
             $changedItems = $this->listingsFacade->changeItems($this->listing, $workedHours, $daysToChange);
         }
     } catch (ShiftEndBeforeStartException $s) {
         $form->addError('Nelze skončit směnu dříve, než začala. Zkontrolujte hodnoty
              v polích Začátek a Konec');
         return;
     } catch (NegativeResultOfTimeCalcException $e) {
         $form->addError('Položku nelze uložit. Musíte mít odpracováno více hodin,
              než kolik strávíte obědem.');
         return;
     }
     if ($values['newListing'] === true) {
         $this->presenter->redirect('Listing:overview', ['year' => $newListing->getYear(), 'month' => $newListing->getMonth()]);
     } else {
         if ($this->presenter->isAjax()) {
             $this->flashMessage('Hodnoty byly úspěšně hromadně změneny.', 'success');
             $this->redrawControl('flashMessage');
             $this->redrawControl('formErrors');
             $this['itemsTable']->refreshTable($changedItems);
         } else {
             $this->redirect('this');
         }
     }
 }
 public function processListingSharing(Form $form, $values)
 {
     $ignoredDays = $form->getHttpData(Form::DATA_TEXT, 'items[]');
     if (count($ignoredDays) == $this->listingResult->getWorkedDays()) {
         $form->addError('Nelze odeslat prázdnou výčetku!
              Nezapomeňte, zaškrtnutím se řádek výčetky nebude sdílet.');
         return;
     }
     try {
         $resultObject = $this->listingFacade->shareListing($this->listing, $values['recipient'], $values['description'], $ignoredDays);
         $this->presenter->flashMessage('Výčetka byla úspěšně sdílena.', 'success');
         if (!$resultObject->hasNoErrors()) {
             $err = $resultObject->getFirstError();
             $this->flashMessage($err['message'], $err['type']);
         }
     } catch (RecipientsNotFoundException $rnf) {
         $form->addError('Nelze zaslat výčetku vybranému uživateli.');
         return;
     } catch (DBALException $e) {
         $form->addError('Nastala chyba při pokusu o sdílení výčetky.
              Zkuste akci opakovat později.');
     }
     $this->redirect('this');
 }