<?php

if (!$_REQUEST ['record'] || $_REQUEST ['record'] == '') {
	die('Brak rekordu');
} else {
	$record = $_REQUEST ['record'];
}

include_once ("modules/EcmReceipts/PDFTemplate/helper.php");

$focus = new EcmReceipt ();
$focus->retrieve($record);

$user = new User ();
$user->retrieve($focus->assigned_user_id);
$labels = return_module_language($focus->ecmlanguage, 'EcmReceipts');
include_once ("include/MPDF57/mpdf.php");
$p = new mPDF('', 'A4', null, 'helvetica', 10, 10, 30, 45, 5, 5);
$mpdf->mirrorMargins = 1;

$db = $GLOBALS ['db'];
// document pdf
// document already exist?
if ($_REQUEST ['pdf_type'] == 'F') {

		// create and save document
		$positions = formatPDFPositions($focus->getPositionList(true), $focus);
		// get header
		$n = $db->query("select * from ecmreceipt_pdf where YEAR(date_entered)=YEAR(NOW()) and stock_id='" . $focus->stock_id . "'");
		$n = $n->num_rows++;
		$n++;
		$focus->document_no = createNumber($n, 5, $focus->stock_id);
		$EcmSysInfo = new EcmSysInfo();
		$header = $EcmSysInfo->getHeaderForModule('EcmInvoiceOuts');
		$footer = $EcmSysInfo->getFooterForModule('EcmInvoiceOuts');
		$content = '';
		include_once ("modules/EcmReceipts/PDFTemplate/content.php");

		
} else {
	// create and save document
	$positions = formatPDFPositions($focus->getPositionList(true), $focus);
	// get header
	$EcmSysInfo = new EcmSysInfo();
	$header = $EcmSysInfo->getHeaderForModule('EcmReceipts');
	$footer = $EcmSysInfo->getFooterForModule('EcmReceipts');
		
	//$header = getHeaderForModule('EcmReceipts');
	//$footer = getFooterForModule('EcmReceipts');
	$content = '';
	include_once ("modules/EcmReceipts/PDFTemplate/content_p.php");

	global $current_user, $app_list_strings;
}
$p->SetHTMLHeader($header);
$p->SetHTMLFooter($footer);
$p->WriteHTML($content);
$p->Output();