<?php
ob_start();
include('includes/session.inc');
$Title = _('Create Invoice');
include('includes/SQL_CommonFunctions.inc');

if (isset($_GET['id'])) {
		$_SESSION['id'] = stripslashes($_GET['id']);
	}
	$opono = $_SESSION['id'];

if (isset($_GET['transno'])) {
		$_SESSION['transno'] = stripslashes($_GET['transno']);
	}
	$paymentno = $_SESSION['transno'];

	$userid = $_SESSION['UserID'];

	// check if the user has set a default bank account for invoices, if not leave it blank


$SQL = "SELECT *
	               
			FROM debtortrans
			WHERE id='" . $opono. "'
			";
	
			$result = DB_query($SQL);
	
			$myrow = DB_fetch_array($result) ;


//$glcodesingle = $myrow['gl_code'];

//$quotedated = date('Y-m-d', strtotime($myrow['entered_date']));
		$quotedate = date('d-m-Y',strtotime($myrow['trandate']));
$yeardate = date('Y',strtotime($myrow['entered_date']));
$monthdate =date('M',strtotime($myrow['entered_date']));
//$departmentid =$myrow['department'];
//$supplierinvoicepaid = explode(", ", $myrow['suppinv_paid']);


$paymentamount =$myrow['ovamount'];



		$userid = $_SESSION['UserID'];
		
$SQLuser = "SELECT email,realname
	               
			FROM www_users
			WHERE userid='" . $userid. "'
			";
	
			$resultuser = DB_query($SQLuser);
	
			$myrowuser = DB_fetch_array($resultuser) ;
		$emailm= $myrowuser['email'];
$realname= $myrow['preparedby'];
		
//get debtor headoffice details:
	
			
$SQLcust = "SELECT name
	               
			FROM debtorsmaster
			WHERE debtorno='" . $myrow['debtorno']. "'
			";
	
			$resultcust = DB_query($SQLcust);
	
			$myrowcust = DB_fetch_array($resultcust) ;	
		
	$username = $_SESSION['UsersRealName'];
		
		$userid = $_SESSION['userid'];	
			$dash = '-';
		
		
		//insert in salesorders to create new sales order/quote. The system can only add quotation and cant update it.
		//$Result = DB_Txn_Begin();

	     
			//get periodno 
	
	
	


$PaperSize = 'A4_Landscape';// PDFStarter.php: $Page_Width=842; $Page_Height=595; $Top_Margin=30; $Bottom_Margin=30; $Left_Margin=40; $Right_Margin=30;
include('includes/PDFStarter.php');
$pdf->addInfo('Title', _('Debtors Journal') );
$pdf->addInfo('Subject', _('Journal') . ' ' . $_GET['opono']);
$FontSize = 12;
$line_height = 12;// Recommended: $line_height = $x * $FontSize.
		
		include('includes/PDFJournalsHeader.inc');

$ListCount ++;
				

		$YPos -= $line_height;// In
//$pdf->SetFont('Freeserif', 'B', 10,' ' , 'false');
	$LeftOvers = $pdf->addTextWrap(100, $YPos,750,$FontSize,_('Date: ').$quotedate._(' Cust Name: ').$myrowcust['name']._(' Cust Account: ').$myrow['account_number']._(' Ref: ').$myrow['reference']._(' Amount: ').$myrow['ovamount'],'left');
$ListCount ++;
$YPos -= $line_height;
$LeftOvers = $pdf->addTextWrap(100, $YPos,750,$FontSize,_('Notes: ').$myrow['notes'],'left');
$ListCount ++;
$YPos -= $line_height;
		
ob_end_clean();
	 //its not an email just print the invoice to PDF
		//$pdf->OutputD('evergreeninvoice_' . $InvoiceNo. '.pdf');

		$pdf->OutputD('DebtorsJournals_Evergreen_' . $paymentno. '.pdf');
		
//	$pdf->OutputD($_SESSION['DatabaseName'] . '_PurchaseOrder_' . $OrderNo . '_' . date('Y-m-d') . '.pdf');
	$pdf->__destruct();
		
	
	
	
	

			
		
			
		
			
		

		
		
			    
		
	


//include('includes/footer.inc'); 

?>
