Esempio n. 1
0
$invoice = new SI_Invoice();
$invoices = $invoice->retrieveSet("WHERE `timestamp` BETWEEN $start_date AND $end_date");
if($invoices === FALSE){
  print("Error retreiving list of invoices!\n");
  print($invoice->getLastError()."\n");
  exit(3);
}

print("Exporting ".count($invoices)." invoices.\n");
foreach($invoices as $invoice){
	if(!is_array($invoice->_lines) || count($invoice->_lines) == 0){
		print("Skipping invoice {$invoice->id}.\n");
		continue;
	}

	$pdf_file = $invoice->getPDF(FALSE);
	if($pdf_file === FALSE){
		print("Error creating PDF invoice.\n");
		print($invoice->getLastError()."\n");
		exit(4);	
	}

	$filename = "invoice_".$invoice->id.'.pdf';
	$fh = fopen($output_directory.DIRECTORY_SEPARATOR.$filename, 'w');
	if($fh == false){
		print("Error opening output file ".$output_directory.DIRECTORY_SEPARATOR.$filename." for writing.\n");
		exit(5);
	}
	fwrite($fh, $pdf_file);
	fclose($fh);
}