<?php

namespace App\Http\ReportGenerator;

use App\Http\ReportGenerator\ReportGenerator;

class PdfReport extends ReportGenerator
{
	public function make()
	{
		$company = $this->company;
		$client = $this->client;
		$supplier = $this->supplier;
		$aux = $this->aux;
		$observation = $this->observation;
		$balance = $this->balance;
		$firma = $this->firma;
		$caption = $this->caption;
		$fiscal = $this->fiscal;

		$headers = $this->headers;
		$query = $this->query;
		$columns = $this->columns;
		$limit = $this->limit;
		$groupByArr = $this->groupByArr;
		$orientation = $this->orientation;
		$view = $this->view;
		$editColumns = $this->editColumns;
		$showTotalColumns = $this->showTotalColumns;
		$styles = $this->styles;
		$showCompany = $this->showCompany;
		$showClient = $this->showClient;
		$showSupplier = $this->showSupplier;
		$showHeader = $this->showHeader;
		$showMeta = $this->showMeta;
		$showAux = $this->showAux;
		$showObservation = $this->showObservation;
		$showBalance = $this->showBalance;
		$showFirma = $this->showFirma;
		$showCaption = $this->showCaption;
		$showFiscal = $this->showFiscal;

		$showNumColumn = $this->showNumColumn;
		$applyFlush = $this->applyFlush;

		$html = \View::make($view, compact('company', 'client', 'supplier', 'aux', 'observation', 'balance', 'firma', 'caption', 'fiscal', 'headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'showCompany', 'showClient', 'showAux', 'showObservation', 'showBalance','showFirma','showCaption','showFiscal', 'showSupplier', 'applyFlush', 'showNumColumn'))->render();

		try {
			$pdf = \App::make('dompdf.wrapper');
		} catch (\ReflectionException $e) {
			try {
				$pdf = \App::make('snappy.pdf.wrapper');
				$pdf->setOption('footer-font-size', 10);
				$pdf->setOption('footer-left', 'Page [page] of [topage]');
				$pdf->setOption('footer-right', 'Date Printed: ' . date('d M Y H:i:s'));
			} catch (\ReflectionException $e) {
				throw new \Exception('Please install either barryvdh/laravel-snappy or laravel-dompdf to generate PDF Report!');
			}
		}

		return $pdf->loadHTML($html)->setPaper($this->paper, $orientation);
	}

	public function stream()
	{
		return $this->make()->stream();
	}

	public function download($filename)
	{
		return $this->make()->download($filename . '.pdf');
	}
}
