<?php
App::import('Vendor','pdfdoc');

$pdfdoc = new PDFDOC();

$pdfdoc->SetPrintHeader(false);
$pdfdoc->SetPrintFooter(false);


$firstPageDone = false;

$companyName = $enquiry['Customer']['name'];
$emailTo = $enquiry['Contact']['email'];
$attention = $enquiry['Contact']['first_name'].' '.$enquiry['Contact']['last_name'];

$fromName = $enquiry['User']['first_name'].' '.$enquiry['User']['last_name'];
$fromEmail = $enquiry['User']['email'];

$enquiryNumber = $enquiry['Enquiry']['title'];

$enquiryCreatedTime = strtotime($enquiry['Enquiry']['created']);



$your_reference = 'Enquiry on '.date('j M Y');

$issue_date = $document['Quote']['date_issued'];

$pdfdoc->docRef = $enquiryNumber;
if($document['Document']['revision'] > 0) {
    $enquiryNumber = $enquiryNumber.'.'.$document['Document']['revision'];
}


foreach($document['DocPage'] as $page) {

    $pdfdoc->AddPage();
    $pdfdoc->Page1Header();
    if($firstPageDone == false) {
	
	$pdfdoc->DetailsBoxHTML($docTypeFullName, $companyName, $emailTo, $attention, $fromName,
		$fromEmail, $enquiryNumber, $your_reference, $issue_date, '30');

	$firstPageDone = true;

    }

    $pdfdoc->pageContent($page['content']);

    $pdfdoc->Page1Footer();

    $pdfdoc->lastPage();

}


$LineItemTable = $this->element('line_items_table');
//echo $LineItemTable;
$pdfdoc->SetHeaderMargin(30);
$pdfdoc->SetFooterMargin(35);
$pdfdoc->SetPrintHeader(true);
$pdfdoc->AddPage();
//$pdfdoc->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml)

$pdfdoc->MultiCell(0, 0, 'PRICING & SPECIFICATIONS', 0, 'C', false, 1, null, null, true, false, false);



$pdfdoc->pageContent($LineItemTable);
$pdfdoc->lastPage();

if($docType == 'quote') {

    $commercialComments = '<div nobr="true">'.$document['Quote']['commercial_comments'].'</div>';
    $pdfdoc->pageContent($commercialComments);
}


$this->element('pdf_output', array('pdfdoc'=>$pdfdoc));


?>

<script type="text/javascript">
window.location.replace("/documents/view/<?=$document['Document']['id']?>");
</script>