<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
include ("../navigation/header.php");
$page_name = "Production-costing";
include ("../navigation/access.php");
$today = date("Y-m-d");

if ($permission_num==1) {

	include ("../navigation/production_sidebar.php");
    include ("../include/date_set.php"); 

$table_name2 = $_SESSION['db_prefix']."_captured_jobs";
$display_query = "
	SELECT job_no,  cust_id, del_date, value, captured_value, cap_result, designer
FROM $table_name2  
WHERE captured='yes' AND   (delivered = 'no' OR delivered IS NULL)
AND job_type = 'Project'
GROUP BY job_no
";
//echo '<br>*****'.$display_query;
$display_result = execsql($display_query);
$display_num = mysql_num_rows($display_result);


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

</head>

<body>
<div class="main_frame" style="height:auto;">
  <div class="page_head_frame">
    <label class="label_page_head">Job costing in progress</label>
  </div>


<div class="page_middle_frame" style="width:710px;" >
<?php if ($display_num!=0) { ?>
<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" language="javascript" src="../jscript/formatted-numbers.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": 1},
                              	{"bVisible": false},
								{"iDataSort": 3},
                              	{"bVisible": false},
								{"bSortable": true},
								{"iDataSort": 6},
                              	{"bVisible": false},
                             	{"iDataSort": 8},
                              	{"bVisible": false},
								{"bSortable": true},
								{"iDataSort": 11},
                              	{"bVisible": false},
								{"iDataSort": 13},
                              	{"bVisible": false},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
								 ]
								 
							 
						 
				} );
			} );
		</script>
  <table width="710" id="scroll_table" class="data_display"">
  <thead>
    <tr>
      <th width="35" align="center">Job no</th>
      <th width="35" align="center">&nbsp;</th>
      <th width="35" align="center">Date</th>
      <th width="35" align="center">&nbsp;</th>
      <th width="169" align="center">Customer</th>
      <th width="55" align="center">Job value</th>
      <th width="17" align="center">&nbsp;</th>
      <th width="55" align="center">Captured<br />
        Quote value</th>
      <th width="21" align="center">&nbsp;</th>
      <th width="62" align="center">Prognose<br />
        in %</th>
      <th width="65" align="center">Actual<br />
        Costing</th>
      <th width="17" align="center">&nbsp;</th>
      <th width="44" align="center">Result</th>
      <th width="18" align="center">&nbsp;</th>
      <th width="44" align="center">in %</th>
      <th width="52" align="center">Designer</th>
      <th width="52" align="center">Sales rep</th>
    </tr>
    </thead>
    
<?php

$job_value_total=0;
$quoted_value_total=0;
$final_value_total=0; 
$result_total=0;
$z=0;
while ($z<$display_num) {
	


$job_no = mysql_result($display_result, $z, "job_no");
$cust_id = mysql_result($display_result, $z, "cust_id");
$delivery_date = mysql_result($display_result, $z, "del_date");
$job_value  = mysql_result($display_result, $z, "value");
$quoted_value  = mysql_result($display_result, $z, "captured_value");
$final_value  = '0';
$result  = '0';
$result_perc  = '0';
$designer  = mysql_result($display_result, $z, "designer");	

$table_name = $_SESSION['db_prefix']."_quotations";
$designer_query = "SELECT seller, designer  FROM $table_name WHERE quote_no = '".$job_no."' ";
$designer_result = mySQL_query($designer_query);
$designer_num = mysql_num_rows($designer_result);
$seller = mysql_result($designer_result, 0, "seller");
$designer2 = mysql_result($designer_result, 0, "designer");


$job_value_total = $job_value_total + $job_value;

include('../include/prog_result_calculate.php');

$quoted_value_total = $quoted_value_total + $captured_total;

$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 = '".$cust_id."' ";
		 			$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");
										
					$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 = '".$job_no."'  ";
					$cust_id_result = mySQL_query($cust_id_query);
					
					$b1 = 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");
										
		$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>";
		
		$jobTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Job no:</td><td width=175>".$job_no."</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>";		
?>

    
    
    
    <tr>
      <td><a href="costing_job.php?job_no=<?php echo $job_no ?>&amp;load=0 " onmouseover="ddrivetip('<?php echo$jobTT?>', 300)"; onmouseout="hideddrivetip()"><?php echo 'J'.$job_no?></a></td>
      <td><a href="costing_job.php?job_no=<?php echo $job_no ?>&amp;load=0 " onmouseover="ddrivetip('<?php echo$jobTT?>', 300)"; onmouseout="hideddrivetip()"><?php echo $job_no ?></a></td>
      <td><?php echo date("d-m-Y", strtotime($delivery_date))?></td>
      <td><?php echo $delivery_date ?></td>
      <td><a href="../sales/customer_details.php?cust_id=<?php echo $cust_id ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 300)"; onmouseout="hideddrivetip()"><?php echo $a2a?></a>&nbsp;</td>
      <td align="right"><?php echo number_format($job_value, 2, '.', ',') ?></td>
      <td align="right"><?php echo $job_value ?></td>
      <td align="right"><?php echo number_format($captured_total, 2, '.', ',') ?></td>
      <td align="right"><?php echo $quoted_value ?></td>
      <td align="right"><?php if ($quoted_value>0) {echo number_format($prog_result, 2, '.', ','); } else { echo '0.00'; } ?></td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td><?php echo $designer ?>&nbsp;</td>
      <td><?php echo $seller ?></td>
    </tr>
    <?php
	$z++;
}
$prognose_perc_average = (($job_value_total-$quoted_value_total)/$job_value_total)*100;

?>
<tfoot>
    <tr>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($job_value_total, 2, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($quoted_value_total, 2, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right"><?php echo number_format($prognose_perc_average, 2, '.', ',') ?></td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td align="right">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    </tfoot>
  </table>
<?php } else { ?>
No data available in this report for the selected time period.
<?php } ?>
  </div>
 
  </div>
  


<?php include ('../navigation/side_bar.php'); ?>




</body>

<?php } else {
$_SESSION['denied_return'] = "production/production_main.php";	
include ("../navigation/production_sidebar.php");?>
<body onload="accessdenied(); return false">
</body>
<?php }
?>

</html>