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

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

if ($permission_num==1) {

	 include ("../navigation/production_sidebar.php");
     include ("../include/date_set.php"); 
	
	$date = $_GET['date'];
	 
	$table_name = $_SESSION['db_prefix']."_production_bill";	 	
	$display_query = "SELECT production_bill_id, date, job_no, follow_no, prod_date FROM $table_name WHERE prod_date >= '".$start."' AND prod_date <= '".$end."' ";
	
		$display_result = execsql($display_query);
		$i = 0;
		$display_num = mysql_num_rows($display_result);
		
		?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>
<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script><script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "500px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 0, "desc" ]],
					"aoColumns": [
								{"iDataSort": 5},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
</head>

<body>
<div class="main_frame">
  <div class="page_head_frame">
    <label class="label_page_head">Production bills</label>
  </div>
  <br />
  <br />
  <br />
  <br />
  <div class="page_middle_frame">
  <form action="production_bill_list.php" method="get" name="dateform" class="today" id="dateform">
    <table width="645" border="0" align="left" cellpadding="0" cellspacing="0" id="table_calendar">
      <tr>
        <td width="41"><label class="label_std">from:</label></td>
        <td width="239"><?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
	 	$myCalendar->writeScript();?></td>
        <td width="42"><label class="label_std">to:</label></td>
        <td width="291"><?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../images/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2014, 2090);
		$myCalendar->writeScript();?>
          <input name="date" type="hidden" id="date" value="1" /></td>
        <td width="90"><label>
            <input name="button5" type="submit" class="linkbutton"  id="button5" value="Select" />
          </label></td>
      </tr>
    </table>
    &nbsp;&nbsp;&nbsp;&nbsp;
  </form>
  </div>
  <br />
  <div class="page_middle_frame">
    <table width="590" id="scroll_table" class="data_display" >
      <thead>
        <tr>
          <th width="68" >Prod Date</th>
          <th width="72" >Job no</th>
          <th width="168" >Customer</th>
          <th width="101" >No of trusses</th>
          <th width="130" >Total FT</th>
          <th width="23" >&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        <?php
    $b9=0;
	$b5tot=0;
	$b6tot=0;
	while($i < $display_num){
		 $b0 = mysql_result($display_result, $i, "job_no");
		 
		 $b8 = mysql_result($display_result, $i, "prod_date");
		 
		 
		 			$table_name = $_SESSION['db_prefix']."_captured_jobs";
					$cust_id_query = "SELECT date, cust_id, project_no, project_place, project_description, designer FROM $table_name WHERE job_no = '".$b0."'  ";
					$cust_id_result = mySQL_query($cust_id_query);
					$b1 = mysql_result($cust_id_result, 0, "cust_id");
					
					$table_name3 = $_SESSION['db_prefix']."_customer";
         			$customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$b1."' ";
		 			$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");
		 						
										
					$b3 = mysql_result($display_result, $i, "production_bill_id");
					$b4 = mysql_result($display_result, $i, "follow_no");
					
					
					$table_name4 = $_SESSION['db_prefix']."_production_bill_lines";
					$number_query = "SELECT SUM(quantity) AS tot_quantity, SUM(quantity*press_points) AS tot_press_points FROM $table_name4 WHERE production_bill_id = '".$b3."' ";
					$number_result = mySQL_query($number_query);
					$b5 = mysql_result($number_result, 0, "tot_quantity");
					$b6 = mysql_result($number_result, 0, "tot_press_points");
					
					$b5tot=$b5tot+$b5;
					$b6tot=$b6tot+$b6;
										
					$b13 = mysql_result($cust_id_result, 0, "date");
					$b9 = mysql_result($cust_id_result, 0, "project_no");
					$b10 = mysql_result($cust_id_result, 0, "project_place");
					$b11 = mysql_result($cust_id_result, 0, "project_description");
					$b12 = mysql_result($cust_id_result, 0, "designer");
					
		$jobTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Job no:</td><td width=175>".$b0."</td></tr><tr><td valign=top>Project no /place:</td><td>".$b9."&nbsp;".$b10."</td></tr><tr><td>Project description:</td><td>".$b11."</td></tr><tr><td>Designer:</td><td>".$b12."</td></tr></table><br><b>Click for details</b>";
					
		$customerTT ="<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>";			
		
		?>
        <tr >
          <td ><?php if ($b8!='') { echo date("d-m-Y", strtotime($b8 )); } ?></td>
          <td align="left"><a href="truss_production.php?&job_no=<?php echo $b0 ?> " onMouseOver="ddrivetip('<?php echo $jobTT?>', 300)"; onMouseOut="hideddrivetip()"><?php echo 'J'.$b0?></a></td>
          <td align="left"><a href="../sales/customer_details.php?cust_id=<?php echo $b1 ?>" onMouseOver="ddrivetip('<?php echo $customerTT?>', 300)"; onMouseOut="hideddrivetip()"><?php echo $a2a?></a></td>
          <td align="right"><?php echo $b5 ?></td>
          <td align="right"><?php echo $b6 ?></td>
          <td align="left"><?php echo $b8 ?></td>
        </tr>
        <?php
		$i++;
		}
	?>
      </tbody>
      <tfoot>
        <tr >
          <td >&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td align="right">Totals:</td>
          <td align="right"><?php echo $b5tot ?></td>
          <td align="right"><?php echo $b6tot ?></td>
          <td align="left">&nbsp;</td>
        </tr>
      </tfoot>
    </table>
    
  </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'); ?>
