<?php

/* $Revision: 1.20 $ */

/*Through deviousness and cunning, this system allows trial balances for any date range that recalcuates the p & l balances
and shows the balance sheets as at the end of the period selected - so first off need to show the input of criteria screen
while the user is selecting the criteria the system is posting any unposted transactions */


$PageSecurity = 8;

include ('includes/session.inc');
$title = _('Purchase Order');
include('includes/SQL_CommonFunctions.inc');
include('includes/AccountSectionsDef.inc'); //this reads in the Accounts Sections array




	include('includes/header.inc');
	echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">';
	
	if(!empty($_GET['order_no']) && is_numeric($_GET['order_no'])){
		$orderno = $_GET['order_no'];
	}


	$SQL = "SELECT *,SUM(pd.unitprice*pd.quantityord) AS ordervalue FROM purchorderdetails pd		
		where pd.orderno = $orderno
		GROUP BY pd.orderno";


	$AccountsResult = DB_query($SQL,
				$db,
				 _('No record were returned by the SQL because'),
				 _('The SQL that failed was:'));
	echo '<div align="right" style="padding-right:10px"><font size=4 color=BLUE><a href="javascript:history.back();">&laquo;Back</a></font></div><br>';
	
	echo '<div class="centre"><font size=4 color=BLUE><b>'. _('Order Number').' : ' . $orderno .'</b></font></div><br>';

	/*show a table of the accounts info returned by the SQL
	Account Code ,   Account Name , Month Actual, Month Budget, Period Actual, Period Budget */

	echo '<table border=1>';
	$TableHeader = "<tr>
			<th>" . _('Item Code') . "</th>
		<th>" . _('Description') . "</th>
		<th>" . _('Quantity') . "</th>
		<th>" . _('UOM') ."</th>
		<th>" . _('Weight') . "</th>
		<th>" . _('Price') ."( INR )</th>
		<th>" . _('Subtotal') .  "( INR )</th>
			</tr>";

	$j = 1;
	
echo $TableHeader;
	$total =0;
	while ($myrow=DB_fetch_array($AccountsResult)) {

	
			$total += $myrow['ordervalue'];
					printf('<tr>
						<td><I>%s</I></td>
						<td class=number><I>%s</I></td>
						<td class=number><I>%s</I></td>
						<td class=number><I>%s</I></td>
						<td class=number><I>%s</I></td>
						<td class=number><I>%s</I></td>
						<td class=number><I>%s</I></td>					
					 </tr>',
					 $myrow['itemcode'],
					 $myrow['itemdescription'],
					 $myrow['quantityord'],
					 $myrow['uom'],
					 $myrow['nw'],
					 $myrow['unitprice'],
					 number_format($myrow['ordervalue'],2));
	
			$j++;	
	
	}	
	
	//end of while loop
	
	$SQL = "SELECT * FROM purchordertax t 
			left join taxauthorities gt on gt.taxid = t.taxgroupid			
		where t.orderno = $orderno";


	$taxResult = DB_query($SQL,
				$db,
				 _('No general ledger accounts were returned by the SQL because'),
				 _('The SQL that failed was:'));
	$taxtotal = 0;		 
	while ($myrow=DB_fetch_array($taxResult)) {
		$taxtotal += $myrow['amount'];
		echo '<tr style="text-align:right">
						<td  colspan="6" align="right"  class=number>'.$myrow['description'].' '.$myrow['tax'].'%</td>
						<td align="right" class=number>'.$myrow['amount'].'</td>						
					 </tr>';
	}
	$gtotal = $total + $taxtotal;
	echo '<tr style="text-align:right">
						<td colspan="6" align="right" class=number><b>Grand Total</b></td>	
						<td align="right" class=number>'.number_format($gtotal,2).'</td>	
					 </tr>';

	



	echo '</table>';

echo '</form>';
include('includes/footer.inc');

?>