<?

include("include/startup.php");

$id = $_REQUEST['sales_id'];
$pdf_name = $_REQUEST['pdf_name'];
$pdf_name = $pdf_name.'-'.$id.'.pdf';


$frontEndURL = $config->frontEndURL;

$url = $frontEndURL."/admin/sales_invoice/index?page=view_sales_invoice_pdf&sales_id=$id&hide_top=1&hide_left=1&create_pdf=1";
			
			
if(isset($_REQUEST['print_url'])){
	
	echo "<a target='_blank' href='$url'>$url</a>";
	die;
}
unlink("".ROOT_DIR_PATH."'sales_invoice_pdfs/".$pdf_name);
$file_path = ROOT_DIR_PATH."/sales_invoice_pdfs/".$pdf_name;
exec("/usr/local/bin/wkhtmltopdf '$url' '$file_path'");
sleep(1);

if(file_exists(ROOT_DIR_PATH."/sales_invoice_pdfs/$pdf_name")){	
	ob_clean();
	header("Location: $frontEndURL"."sales_invoice_pdfs/$pdf_name");
	exit;
}

?>