public function generatePdf(SubmitButton $button)
 {
     $values = $button->getForm()->getValues(true);
     $items = $this->listingItemsReader->findListingsItems([$this->listingResult->getListingId()]);
     $listing = $this->listingResult->getListing();
     $listingData = ['l_id' => $listing->id, 'l_year' => $listing->year, 'l_month' => $listing->month, 'l_description' => $listing->description, 'l_hourlyWage' => $listing->hourlyWage, 'u_id' => $listing->user->id, 'u_name' => $listing->user->name, 'worked_days' => $this->listingResult->getWorkedDays(), 'worked_hours' => $this->listingResult->getWorkedHours(), 'total_worked_hours_in_sec' => $this->listingResult->getTotalWorkedHours()->toSeconds(), 'lunch_hours' => $this->listingResult->getLunchHours(), 'other_hours' => $this->listingResult->getOtherHours()];
     /** @var IListingPdfFile $pdf */
     $pdf = $this->listingPDFGenerator->generate($listingData, $items, $values);
     $response = new Nette\Application\Responses\FileResponse($pdf->getStoragePath(), $pdf->getFileName());
     $this->presenter->sendResponse($response);
 }
 /**
  * @param Listing $baseListing
  * @param Listing $listingToMerge
  * @param array $selectedCollisionItems
  * @param User $ownerOfOutputListing
  * @return Listing
  * @throws NoCollisionListingItemSelectedException
  * @throws \Exception
  */
 public function mergeListings(Listing $baseListing, Listing $listingToMerge, array $selectedCollisionItems = [], User $ownerOfOutputListing)
 {
     if (!$this->haveListingsSamePeriod($baseListing, $listingToMerge)) {
         throw new RuntimeException('Given Listings must have same Period(Year and Month).');
     }
     try {
         $this->em->beginTransaction();
         $items = $this->itemsService->getMergedListOfItems($this->listingItemsReader->findListingItems($baseListing->getId()), $this->listingItemsReader->findListingItems($listingToMerge->getId()), $selectedCollisionItems);
         $newListing = new Listing($baseListing->year, $baseListing->month, $ownerOfOutputListing);
         $this->em->persist($newListing);
         foreach ($items as $item) {
             /** @var ListingItem $item */
             $item->setListing($newListing);
             $this->em->persist($item);
         }
         $this->em->flush();
         $this->em->commit();
         return $newListing;
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         $this->onError('Merging of listings #id(' . $baseListing->getId() . ') and #id(' . $listingToMerge->getId() . ') failed.', $e, self::class);
         throw $e;
     }
 }
 /**
  * @param ListingItem $listingItem
  * @return ListingItem
  * @throws ListingItemNotFoundException
  */
 private function provideItemForUpShifting(ListingItem $listingItem)
 {
     // we do NOT want to shift the first item
     if ($listingItem->day <= 1) {
         throw new ShiftItemUpException();
     }
     return $this->listingItemReader->getAdjacentItem($listingItem, ListingItemsReader::ITEM_UPPER);
 }
 public function generate($year, User $user, array $settings = [])
 {
     $listings = $this->listingsReader->getAnnualListingsForPDFGeneration($year, $user);
     $listings = Arrays::associate($listings, 'l_id');
     $items = $this->listingItemsReader->findListingsItems(array_keys($listings));
     $pdfFiles = [];
     $listingItemsCollection = [];
     /**
      * @var int $listingId
      * @var IListingPdfSource $pdfSource
      */
     foreach ($listings as $listingId => $listing) {
         foreach ($items as $key => $item) {
             if ($item->getListing()->getId() == $listingId) {
                 $listingItemsCollection[] = $item;
                 unset($items[$key]);
             }
         }
         $pdfFiles[] = $this->listingPdfGenerator->generate($listing, $listingItemsCollection, $settings);
         $listingItemsCollection = [];
     }
     $zipStorageFilePath = $this->storagePath . '/' . $user->getId() . '/' . $year . "/vycetky-{$year}.zip";
     return $this->zipFiles($pdfFiles, $zipStorageFilePath);
 }
 /**
  * @param Listing $baseListing
  * @param Listing $listing
  * @return array
  */
 public function getMergedListingsItemsForEntireTable(Listing $baseListing, Listing $listing)
 {
     if (!$this->haveListingsSamePeriod($baseListing, $listing)) {
         throw new InvalidArgumentException('Given Listings must have same Period(Year and Month).');
     }
     $items = $this->itemsService->mergeListingItems($this->listingItemsReader->findListingItems($baseListing->getId()), $this->listingItemsReader->findListingItems($listing->getId()));
     $days = $baseListing->getNumberOfDaysInMonth();
     $result = array();
     for ($day = 1; $day <= $days; $day++) {
         if (!array_key_exists($day, $items)) {
             $result[$day][] = new FillingItem(new \DateTime($baseListing->year . '-' . $baseListing->month . '-' . $day));
         } else {
             foreach ($items[$day] as $key => $item) {
                 $itemDec = new MergeableListingItem($item);
                 $itemDec->setAsItemFromBaseListing(true);
                 if ($key != 0) {
                     $itemDec->setAsItemFromBaseListing(false);
                 }
                 $result[$day][] = $itemDec;
             }
         }
     }
     return $result;
 }
 /**
  * @param Listing $listing
  * @return IDisplayableItem[]
  */
 public function generateEntireTable(Listing $listing)
 {
     $listingItems = $this->listingItemsReader->findListingItems($listing);
     $displayableItems = $this->prepareDisplayableItemsCollection($listingItems);
     return $this->itemsService->generateEntireTable($displayableItems, $listing->getPeriod());
 }