<head>
<?php 
include ("../navigation/header.php");

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {

	 include ("../navigation/store_sidebar.php");
	
		$width=$_GET['width'];
		$depth=$_GET['depth'];	
		$class=$_GET['class'];		  
		$subCat='timber';
		
		$table_name5 = $_SESSION['db_prefix']."_captured_timber";
		$table_name6 = $_SESSION['db_prefix']."_captured_jobs";
		$table_name8 = $_SESSION['db_prefix']."_captured_cash_sale";
		$table_name7 = $_SESSION['db_prefix']."_customer";
		
$timber_query = "
SELECT 
$table_name6.cust_id, 
cap_job, 
cap_timber_group, 
cap_timber, 
cap_timber_name, 
SUM(prereserved) AS prereserved, 
SUM(reserved ) AS reserved
FROM $table_name5, $table_name6
WHERE $table_name5.cap_job=$table_name6.job_no 
AND cap_depth= '".$depth."' 
AND cap_width = '".$width."' 
AND cap_class= '".$class."' 
AND ( (prereserved<>0) OR (reserved<>0)) 
GROUP BY $table_name5.cap_job 
";
$timber_result = mySQL_query($timber_query);
$timber_num = mysql_num_rows($timber_result);


$timber_cash_query = "
SELECT 
$table_name8.cust_id, 
cap_job, 
cap_timber_group, 
cap_timber, 
cap_timber_name, 
SUM(reserved ) AS reserved
FROM $table_name5, $table_name8
WHERE $table_name5.cap_job=$table_name8.job_no 
AND cap_depth= '".$depth."' 
AND cap_width = '".$width."' 
AND cap_class= '".$class."' 
AND ( (reserved<>0)) 
GROUP BY $table_name5.cap_job 
";

$timber_cash_result = mySQL_query($timber_cash_query);
$timber_cash_num = mysql_num_rows($timber_cash_result);

?>
<script type="text/JavaScript">
<!--
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<link rel="stylesheet" href="../window/modal.css" type="text/css" />
<script type="text/javascript" src="../window/modal.js"></script>
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<!--reference to main.css removed-->

</head>

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>
<div class="main_frame">
  <!--reference to main.css removed-->
  <div class="page_head_frame">
    <table width="656" border="0" >
      <tr>
      <td width="537"><label class="label_page_head">Timber Reserved List</label>&nbsp;&nbsp;<label class="label_page_head_2"> <?php if ($width!='all') { echo $depth." x ".$width." (".$class.")" ; } ?></label></td>
      <td width="103" onClick="MM_goToURL('parent','store_timber_list.php?width=all&depth=&class=&single=');return document.MM_returnValue">&nbsp;</td>
    </tr>
</table>
  </div>
  <div class="scroll_frame_long" style="height:450px;">
  
    <table width="672" id="table_list" class="sortable-onload-0 rowstyle-alt no-arrow "  >
      <thead>
        <tr>
          <th width="208" height="44" rowspan="2" align="left" class="sortable-text">Timber Name</th>
          <th width="76" rowspan="2" align="left" class="sortable-text">Timber</th>
          <th width="56" rowspan="2" align="left" class=\"sortable-text"><span class="sortable-numeric">Used for</span></th>
          <th width="56" rowspan="2" align="left" class=\"sortable-text">Job no</th>
          <th width="116" rowspan="2" align="left" class=\"sortable-text">Customer</th>
          <th colspan="2" class=\"sortable-numeric">Reserved
          </th>
        </tr>
        <tr>
          <th width="64" class=\"sortable-numeric"><span class="\&quot;sortable-text&quot;"><span class="sortable-numeric">Estimate</span></span></th>
          <th width="64" class="sortable-numeric"><span class="\&quot;sortable-numeric&quot;">Actual</span></th>
        </tr>
      </thead>
      <tbody>
        <?php 
		$a4tot='';
		$a5tot='';
		$i=0;
		while ($i<$timber_num) {
			$a6 = mysql_result($timber_result, $i, "cap_timber_group");
			$a5 = mysql_result($timber_result, $i, "reserved");
			
			//if (($a6=='Cash sale') AND ($a5==0)) {
//				$i++;
//			}
//			else {
			
			$a1 = mysql_result($timber_result, $i, "cap_job");
			$a2 = mysql_result($timber_result, $i, "cust_id");
			$a3 = mysql_result($timber_result, $i, "cap_timber_name");
			
			$a5 = mysql_result($timber_result, $i, "reserved");
			$a6 = mysql_result($timber_result, $i, "cap_timber_group");
			
			if ($a6!='Cash sale') {
			      $a4 = mysql_result($timber_result, $i, "prereserved"); 
			}
			else {
				$a4=0;
			}
			
			$a7 = mysql_result($timber_result, $i, "cap_timber");
			
			$a4tot = $a4tot + $a4;
			$a5tot = $a5tot + $a5;
			
			$customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name7 WHERE cust_id = '".$a2."' ";
		 	$customer_result = mySQL_query($customer_query);
         	$a2a = mysql_result($customer_result, 0, "comp_name");
		 	$a2b = mysql_result($customer_result, 0, "bag_box");
		 	$a2c = mysql_result($customer_result, 0, "box_no");
		 	$a2d = mysql_result($customer_result, 0, "postal_place");
		 	$a2e = mysql_result($customer_result, 0, "phone");
		 	$a2f = mysql_result($customer_result, 0, "contact_1");
			
			$customerTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
			
			if ($a6=='Cash sale')  { 
			$job_query = "SELECT project_no, project_place, project_description FROM $table_name8 WHERE job_no= '".$a1."' ";
			$job_result = mySQL_query($job_query);
			$job_num = mysql_num_rows($job_result);
			$b1 = mysql_result($job_result, 0, "project_no");
			$b2 = mysql_result($job_result, 0, "project_place");
			$b3 = mysql_result($job_result, 0, "project_description");
			$b4 = '';
			}
			else {
			$job_query = "SELECT project_no, project_place, project_description, designer FROM $table_name6 WHERE job_no= '".$a1."' ";
			$job_result = mySQL_query($job_query);
			$job_num = mysql_num_rows($job_result);
			$b1 = mysql_result($job_result, 0, "project_no");
			$b2 = mysql_result($job_result, 0, "project_place");
			$b3 = mysql_result($job_result, 0, "project_description");
			$b4 = mysql_result($job_result, 0, "designer");
			}
						
			$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Project no:</td><td width=175>".$b1."</td></tr><tr><td>Project place:</td><td>".$b2."</td></tr><tr><td>Description:</td><td>".$b3."</td></tr><tr><td>Designer:</td><td>".$b4."</td></tr></table><br><b>Click for details</b>"; 
			
			?>
			
        <tr class="alt">
          <td><?php echo $a3 ?></td>
          <td><?php echo $a7 ?>&nbsp;</td>
          <td><?php echo $a6 ?></td>
          <td><a href="../production/captured_job.php?job_no=<?php echo $a1?> " onMouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo 'J'.$a1 ?></a></td>
          <td><a href="../sales/customer_details.php?cust_id=<?php echo $a2?>" onMouseover="ddrivetip('<?php echo $customerTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
          <td align="right"><?php if ($a4!=0) { echo $a4; }?></td>
          <td align="right"><?php if($a5!=0) {echo $a5; }?></td>
        </tr>
        <?php 
		$i++;
    	}
		//}
    	?>
        
        <?php 
		
		$i=0;
		while ($i<$timber_cash_num) {
			$a1 = mysql_result($timber_cash_result, $i, "cap_job");
			$a2 = mysql_result($timber_cash_result, $i, "cust_id");
			$a3 = mysql_result($timber_cash_result, $i, "cap_timber_name");
			//$a4 = mysql_result($timber_cash_result, $i, "prereserved");
			$a5 = mysql_result($timber_cash_result, $i, "reserved");
			$a6 = mysql_result($timber_cash_result, $i, "cap_timber_group");
			$a7 = mysql_result($timber_cash_result, $i, "cap_timber");
			
			//$a4tot = $a4tot + $a4;
			$a5tot = $a5tot + $a5;
			
			$customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name7 WHERE cust_id = '".$a2."' ";
		 	$customer_result = mySQL_query($customer_query);
         	$a2a = mysql_result($customer_result, 0, "comp_name");
		 	$a2b = mysql_result($customer_result, 0, "bag_box");
		 	$a2c = mysql_result($customer_result, 0, "box_no");
		 	$a2d = mysql_result($customer_result, 0, "postal_place");
		 	$a2e = mysql_result($customer_result, 0, "phone");
		 	$a2f = mysql_result($customer_result, 0, "contact_1");
			
			$customerTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
			
			if ($a6=='Cash sale')  { 
			$job_query = "SELECT project_no, project_place, project_description FROM $table_name8 WHERE job_no= '".$a1."' ";
			$job_result = mySQL_query($job_query);
			$job_num = mysql_num_rows($job_result);
			$b1 = mysql_result($job_result, 0, "project_no");
			$b2 = mysql_result($job_result, 0, "project_place");
			$b3 = mysql_result($job_result, 0, "project_description");
			$b4 = '';
			}
			else {
			$job_query = "SELECT project_no, project_place, project_description, designer FROM $table_name6 WHERE job_no= '".$a1."' ";
			$job_result = mySQL_query($job_query);
			$job_num = mysql_num_rows($job_result);
			$b1 = mysql_result($job_result, 0, "project_no");
			$b2 = mysql_result($job_result, 0, "project_place");
			$b3 = mysql_result($job_result, 0, "project_description");
			$b4 = mysql_result($job_result, 0, "designer");
			}
						
			$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Project no:</td><td width=175>".$b1."</td></tr><tr><td>Project place:</td><td>".$b2."</td></tr><tr><td>Description:</td><td>".$b3."</td></tr><tr><td>Designer:</td><td>".$b4."</td></tr></table><br><b>Click for details</b>"; 
			
			?>
			
        <tr class="alt">
          <td><?php echo $a3 ?></td>
          <td><?php echo $a7 ?>&nbsp;</td>
          <td><?php echo $a6 ?></td>
          <td><a href="../production/captured_job.php?job_no=<?php echo $a1?> " onMouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo 'J'.$a1 ?></a></td>
          <td><a href="../sales/customer_details.php?cust_id=<?php echo $a2?>" onMouseover="ddrivetip('<?php echo $customerTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
          <td align="right">&nbsp;</td>
          <td align="right"><?php if($a5!=0) {echo $a5; }?></td>
        </tr>
        <?php 
		$i++;
    	}
    	?>
        
        
        </tbody>
        <tfoot>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right">totals:</td>
        <td align="right"><?php if ($a4tot!='') {echo number_format($a4tot, 2, '.', ',');} ?></td>
        <td align="right"><?php if ($a5tot!='') {echo number_format($a5tot, 2, '.', ',');} ?></td>
      </tfoot>
      
    </table>
    <div align="left">
     
    </div><br>

    <div align="left"></div>
    
    
  </div>
  

</div>



</body>
<?php } else { 
    $_SESSION['denied_return'] = "store/store_main.php";	?>
<body onLoad="accessdenied(); return false">
</body>
<?php }
?>
<?php include ('../navigation/side_bar.php'); ?>
