<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--reference to main.css removed-->
<?php
include('../include/session.php');
?>

<?php
$job_card_no=$_GET['job_card_no'];
$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_query = "SELECT * FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_result = mySQL_query($job_query);
//$job_card_no = mysql_result($job_result, 0, "job_card_no");
$cust_id = mysql_result($job_result, 0, "cust_id");
$quote_note = mysql_result($job_result, 0, "quote_note");
$value = mysql_result($job_result, 0, "value");
$order_date = mysql_result($job_result, 0, "date");
$del_date = mysql_result($job_result, 0, "del_date");
$project_description = mysql_result($job_result, 0, "project_description");

$project_no = mysql_result($job_result, 0, "project_no");
$project_place = mysql_result($job_result, 0, "project_place");
$project_area = mysql_result($job_result, 0, "project_area");
$deliver_date = mysql_result($job_result, 0, "del_date");
$forman = mysql_result($job_result, 0, "forman");
$labour_charge = mysql_result($job_result, 0, "labour_charge");
$travel_expense = mysql_result($job_result, 0, "travel_expense");
$accomodation_expense = mysql_result($job_result, 0, "accomodation_expense");

$table_name2 = $_SESSION['db_prefix']."_employee";
$employee_query = "SELECT emp_first_name, emp_last_name FROM $table_name2 WHERE emp_id ='".$forman."' ";
$employee_result = mySQL_query($employee_query);
$employee_num = mysql_num_rows($employee_result);	
$forman_name = mysql_result($employee_result, 0, "emp_first_name").' '.mysql_result($employee_result, 0, "emp_last_name"); 


$table_name = $_SESSION['db_prefix']."_order_job_lines";
$line_query = "SELECT *  FROM $table_name WHERE  job_card_no =  '".$job_card_no."' AND store_item_id>0";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);


$table_name = $_SESSION['db_prefix']."_order_job_lines";
$line2_query = "SELECT *  FROM $table_name WHERE  job_card_no =  '".$job_card_no."' AND store_item_id IS NULL";
$line2_result = mySQL_query($line2_query);
$line2_num = mysql_num_rows($line2_result);

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

<!--jscript-->
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script>

</head>

<body>
<?php
include ("../navigation/header.php");
$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>
<div class="main_frame">
  <div class="page_head_frame">
          <table width="809" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><label class="label_page_head">Job card</label>
                &nbsp;&nbsp;&nbsp;
                <label class="label_page_head_2"> <?php echo $a0 ?></label></td>
            </tr>
          </table>
          </div>
          <div class="page_middle_frame">
<div class="page_inside_frame">
<?php 
include('../include/customer_block.php');
?>
</div>    
<div class="page_inside_frame">
<table width="650" id="table_details_display">
    <tr>
      <td align="left" valign="top">Project:</td>
      <td align="left" valign="top"><?php  echo $project_description;  ?></td>
      <td align="left" valign="top"><?php echo 'Job card no:'; ?></td>
      <td align="left" valign="top"><?php echo $job_card_no;  ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Forman:</td>
      <td align="left" valign="top"><?php echo $forman_name ?></td>
      <td align="left" valign="top">&nbsp;</td>
      <td align="left" valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="top"><?php  echo 'Order date:';?></td>
      <td width="131" align="left" valign="top"><?php  echo date("d-m-Y", strtotime($order_date));  ?></td>
      <td width="101" align="left" valign="top"><?php  echo 'Job value'; ?></td>
      <td width="277" align="left" valign="top"><?php   echo number_format($value, 2, '.', ','); ?></td>
    </tr>
    <tr>
      <td align="left" valign="top">Delivery date:</td>
      <td colspan="3" align="left" valign="top"><?php echo date("d-m-Y", strtotime($deliver_date));  ?></td>
      </tr>
    <tr>
      <td width="121" align="left" valign="top">Project place:</td>
      <td colspan="3" align="left" valign="top"><?php echo $project_area?>&nbsp;&nbsp;<?php echo $project_area?>&nbsp;&nbsp;<?php echo $project_place?></td>
      </tr>
    <tr>
      <td align="left" valign="top">Notes:</td>
      <td colspan="3" align="left" valign="top"><?php echo $quote_note ?></td>
    </tr>
  </table>
</div>  

<div class="page_inside_frame">
Project costing:
<table width="650" id="table_display">
  <tr>
    <td width="295">Labour charges:</td>
    <td width="189">&nbsp;</td>
    <td width="150" align="right"><?php if ($labour_charge!='') {echo number_format($labour_charge, 2, '.', ',');}?></td>
  </tr>
  <tr>
    <td>Travel expense:</td>
    <td>&nbsp;</td>
    <td align="right"><?php if ($travel_expense!='') {echo number_format($travel_expense, 2, '.', ',');}?></td>
  </tr>
  <tr>
    <td>Accomodation expense:</td>
    <td>&nbsp;</td>
    <td align="right"><?php if ($accomodation_expense!='') {echo number_format($accomodation_expense, 2, '.', ',');}?></td>
  </tr>
  <tr>
    <td>&nbsp;<?php $sub_total_1 = $_SESSION['labour'] + $_SESSION['travel'] + $_SESSION['accomodation']; ?></td>
    <td align="right">Sub total:</td>
    <td align="right"><?php echo number_format($sub_total_1, 2, '.', ',') ?>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
Store items
<table width="650" id="table_display" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="91" align="left" valign="top">Group</td>
            <td width="36" align="center" valign="top">Unit</td>
            <td width="56" align="center" valign="top">quantity</td>
            <td width="66" align="center" valign="top">price</td>
            <td width="152" align="center" valign="top">total</td>
            </tr>
          <?php
				$i=0;
				$sub_total_2=0;
				while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "order_line_id");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					 
					$a5=$a2*$a3;
					$sub_total_2=$sub_total_2+$a5;
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1a ?></td>
            <td valign="top"><?php echo $a4a ?></td>
            <td valign="top"><?php echo $a3a ?></td>
            <td valign="top"><?php echo $a2 ?></td>
            <td align="right" valign="top"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
            <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',');?></td>
            </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
          <tr>
            <td colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">Total:</td>
            <td align="right" valign="top"><?php echo number_format($sub_total_2, 2, '.', ',') ?></td>
            </tr>
          </table>
        <br>
<br>
Non store items
    <table width="650" id="table_display" >
          <tr>
            <td height="26" colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="center" valign="top">&nbsp;</td>
            <td align="center" valign="top">&nbsp;</td>
            <td align="center" valign="top">&nbsp;</td>
            <td align="center" valign="top">&nbsp;</td>
          </tr>
          <tr>
            <td height="26" colspan="2" align="left" valign="top">Item</td>
            <td width="37" align="center" valign="top">&nbsp;</td>
            <td width="55" align="center" valign="top">quantity</td>
            <td width="66" align="center" valign="top">price</td>
            <td width="152" align="center" valign="top">total</td>
          </tr>
          <?php
				$i=0;
				$sub_total_3=0;
				while ($i<$line2_num){
					 $a0 = mysql_result($line2_result, $i, "order_line_id");
					 $a1 = mysql_result($line2_result, $i, "item_name");
					 $a2 = mysql_result($line2_result, $i, "quantity");
					 $a3 = mysql_result($line2_result, $i, "price");
					 $a4 = mysql_result($line2_result, $i, "order_no");
					 
					$a5=$a2*$a3;
					$sub_total_3=$sub_total_3+$a5;
					 
				 ?>
          <tr>
            <td colspan="2" valign="top"><?php echo $a1 ?></td>
            <td valign="top">&nbsp;</td>
            <td valign="top"><?php echo $a2 ?></td>
            <td align="right" valign="top"><?php echo $a3  ?>&nbsp;</td>
            <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',')?></td>
          </tr>
          <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
          <tr>
            <td colspan="2" align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">&nbsp;</td>
            <td align="left" valign="top">Total:</td>
            <td align="right" valign="top"><?php echo number_format($sub_total_3, 2, '.', ',') ?></td>
          </tr>
      </table>
    <br>
    <table width="650"  id="table_display" >
      <tr>
        <td width="486">Project total:&nbsp;<?php $all_total = $sub_total_1 + $sub_total_2 + $sub_total_3; ?></td>
        <td width="152" align="right"><?php echo number_format($all_total, 2, '.', ',') ?></td>
      </tr>
  </table>
    <p>&nbsp;</p>
</div>      



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


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