<?php

/* $Revision: 1.9 $ */

$PageSecurity = 2;

include('includes/session.inc');
$title = _('Work Orders Report');
include('includes/header.inc');

echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/magnifier.png" title="' . _('Search') . '" alt="">' . ' ' . $title;
echo '<form action=' . $_SERVER['PHP_SELF'] .'?' .SID . ' method=post>';



			
			  $SQL = "SELECT workorders.wo,
					woitems.stockid,
					workorders.loccode,
					locations.locationname,
					stockmaster.description,
					woitems.qtyreqd,
					woitems.qtyrecd,
					bom.workcentreadded,
					workorders.requiredby
					FROM workorders
					INNER JOIN woitems ON workorders.wo=woitems.wo
					INNER JOIN stockmaster ON woitems.stockid=stockmaster.stockid
					INNER JOIN locations ON workorders.loccode=locations.loccode
					INNER JOIN bom ON woitems.stockid=bom.parent
					group BY workorders.wo,
							 woitems.stockid";

	$ErrMsg = _('No works orders were returned by the SQL because');
	$WorkOrdersResult = DB_query($SQL,$db,$ErrMsg);

	/*show a table of the orders returned by the SQL */

	echo '<table cellpadding=2 colspan=7 WIDTH=100%>';


	$tableheader = "<tr>
				<th>" . _('Work order no') . "</th>
				<th>" . _('Location') . "</th>
				<th>" . _('Works center') . "</th>
				<th>" . _('Item') . "</th>
				<th>" . _('Item Description') . "</th>
				<th>" . _('Quantity Required') . "</th>
				<th>" . _('Quantity Received') . "</th>
				<th>" . _('Quantity Outstanding') . "</th>
				<th>" . _('Required Date') . "</th>
				</tr>";

	echo $tableheader;

	$j = 1;
	$k=0; //row colour counter
	while ($myrow=DB_fetch_array($WorkOrdersResult)) {
	 $sqlget='select * from workcentres where code="'.$myrow['workcentreadded'].'"';
	$rs=DB_query($sqlget,$db,$ErrMsg);
	$rsget=DB_fetch_array($rs);

		if ($k==1){
			echo '<tr class="EvenTableRows">';
			$k=0;
		} else {
			echo '<tr class="OddTableRows">';
			$k++;
		}


		$FormatedRequiredByDate = ConvertSQLDate($myrow['requiredby']);


		printf("<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td align=right>%s</td>
				<td align=right>%s</td>
				<td align=right>%s</td>
				<td>%s</td>
				</tr>",
				
				$myrow['wo'],
				$myrow['locationname'],
				$rsget['description'],
				$myrow['stockid'],
				$myrow['description'],
				$myrow['qtyreqd'],
				$myrow['qtyrecd'],
				$myrow['qtyreqd']-$myrow['qtyrecd'],
				$FormatedRequiredByDate);

		$j++;
		If ($j == 12){
			$j=1;
			echo $tableheader;
		}
	}

	echo '</table>';


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