<!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" />

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<?php
include ("../navigation/header.php");
$page_name = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/sales_sidebar.php");

$cust_id = $_GET['cust_id'];
?>
</head>
<?php

	
$table_name2 = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);	
$a1 = mysql_result($customer_result, 0, "account_type");
if ($a1=="corporate") { $a0 = mysql_result($customer_result, 0, "comp_name"); } else { $a0 = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".mysql_result($customer_result, 0, "comp_name"); }


$a5 = mysql_result($customer_result, 0, "contact_1");
$a6 = mysql_result($customer_result, 0, "status");
$a7 = mysql_result($customer_result, 0, "bag_box");
$a8 = mysql_result($customer_result, 0, "box_no");
$a9 = mysql_result($customer_result, 0, "postal_place");
$a10 = mysql_result($customer_result, 0, "phys_address");
$a11 = mysql_result($customer_result, 0, "phys_place");
$a12 = mysql_result($customer_result, 0, "web_site");
$a13 = mysql_result($customer_result, 0, "vat_no");
$a15 = mysql_result($customer_result, 0, "email_2");
$a23 = mysql_result($customer_result, 0, "fax");
$a24 = mysql_result($customer_result, 0, "phone");
$a26 = mysql_result($customer_result, 0, "country");
$a29 = mysql_result($customer_result, 0, "email_1");
$a30 = mysql_result($customer_result, 0, "cell_1");
$a32 = mysql_result($customer_result, 0, "cell_2");
$a35 = mysql_result($customer_result, 0, "contact_2");
$a36 = mysql_result($customer_result, 0, "notes");

$table_name = $_SESSION['db_prefix']."_quotations";
$quote_query = "SELECT  quote_no  FROM $table_name WHERE cust_id ='".$cust_id."' ";
$quote_result = mySQL_query($quote_query);
$quote_num = mysql_num_rows($quote_result);

$table_name = $_SESSION['db_prefix']."_captured_jobs";
$job_query = "SELECT  job_no, project_no, project_place, project_description, designer, value, delivered  FROM $table_name WHERE cust_id ='".$cust_id."' ";
$job_result = mySQL_query($job_query);
$job_num = mysql_num_rows($job_result);

?>
<script type="text/javascript" src="../jscript/tablesort.js"></script>

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>
<?php include ('../include/tooltip.php'); ?>

<div class="main_frame" style="height:auto;">
  <table id="tableMain" > <!--begin of tableMain-->
    <tr>
      <td width="830" height="62" valign="top" ><div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><label class="label_page_head">Customer:</label>&nbsp;&nbsp;&nbsp;<label class="label_page_head_2"> <?php echo $a0 ?></label></td>
            </tr>
        </table>
      </div>
        <br />

<br /></td> <!--center of tableMain-->
</tr>
<tr>
<td height="93"> <!--center of tableMain-->
<div class="page_middle_frame">
<div align="left">Company details</div>
  <table width="680" id="table_details_display">
    <tr>
      <td width="101" height="25">Client name:</td>
      <td colspan="4"><b><?php echo $a0?></b></td>
      </tr>
    <tr>
      <td height="25">&nbsp;</td>
      <td width="148">&nbsp;</td>
      <td width="163">&nbsp;</td>
      <td width="141">&nbsp;</td>
      <td width="103">&nbsp;</td>
    </tr>
  </table>
</div>
</td>
</tr>
<tr>
<td>
<div class="page_middle_frame">
<div align="left">Contact details</div>
  <table width="679" id="table_details_display">
    <tr>
      <td width="132" height="25">Postal address:</td>
      <td width="131"><b><?php echo $a7." ".$a8?></b></td>
      <td width="84">Postal place:</td>
      <td width="99"><b><?php echo $a9?></b></td>
      <td width="69">Country:</td>
      <td width="136"><b><?php echo $a26?></b></td>
    </tr>
    <tr>
      <td height="25">Physical address:</td>
      <td><b><?php echo $a10?></b></td>
      <td>Place:</td>
      <td><b><?php echo $a11?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">Phone:</td>
      <td><b><?php echo $a24?></b></td>
      <td>Fax:</td>
      <td><b><?php echo $a23?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">VAT registration no::</td>
      <td><b><?php echo $a13?></b></td>
      <td>web site:</td>
      <td colspan="3"><b><a href="http://<?php echo $a12?>" target="_blank"><?php echo $a12?></a></b></td>
      </tr>
  </table>
</div>

</td>
</tr>
<tr>
<td height="220">
<div class="page_middle_frame">
<div align="left">Company contacts</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="132" height="25">Contact 1:</td>
      <td width="130"><b><?php echo $a5?></b></td>
      <td width="70">Cell:</td>
      <td width="110"><b><?php echo $a30 ?></b></td>
      <td width="76">&nbsp;</td>
      <td width="132">&nbsp;</td>
    </tr>
    <tr>
      <td height="25">e-mail:</td>
      <td colspan="2"><b><a href="mailto:<?php echo $a29 ?>"><?php echo $a29 ?></a></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">Contact 2:</td>
      <td><b><?php echo $a35?></b></td>
      <td>Cell:</td>
      <td><b><?php echo $a32?></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="25">e-mail:</td>
      <td colspan="2"><b><a href="mailto:<?php echo $a15 ?>"><?php echo $a15 ?></a></b></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>

<div class="page_middle_frame">
<div align="left">Miscelaneous</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="131" height="25">Notes</td>
      <td width="535"><b><?php echo $a36?></b></td>
    </tr>
  </table>
</div>

<div class="page_middle_frame">
<div align="left">Quotation history</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="131" height="25">Previous quotations:</td>
      <td width="535">
      <?php 
	  $i=0;
	  while ($i<$quote_num) {
		  $qn = mysql_result($quote_result, $i, "quote_no");
		  $table_name = $_SESSION['db_prefix']."_quotations";
          $quotation_query = "SELECT  quotation_date, value, result  FROM $table_name WHERE quote_no= '".$qn."' ";
          $quotation_result = mySQL_query($quotation_query);
          $qn1 = mysql_result($quotation_result, 0, "quotation_date");
		  $qn3 = mysql_result($quotation_result, 0, "result");
		  
		  $table_name = $_SESSION['db_prefix']."_quotation_lines";
	$line_query = "SELECT  quote_item_text, quote_item_price   FROM $table_name WHERE quote_number = '".$qn."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	$l=0;
	$a7=0;
	$line_text="";
	$products=mysql_result($line_result, 0, "quote_item_text");
		
	while($l<$line_num) {
	   $price=mysql_result($line_result, $l, "quote_item_price");
	   $a7=$price+$a7;	
	  
	   $line = mysql_result($line_result, $l, "quote_item_text");
	   $line_text = $line_text."&nbsp;-&nbsp;".$line." @ P ".number_format($price, 2, '.', ',')."<br>";
	   $l++;
	   
	}
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$qn."' ORDER BY note_date DESC";
	$notes_result = mySQL_query($notes_query);
	$notes_num = mysql_num_rows($notes_result);
	$notes_text='';
	$m=0;
	while ($m<$notes_num) {
		$notes1 = date("d-m-Y", strtotime(mysql_result($notes_result, $m, "note_date")))." ".mysql_result($notes_result, $m, "seller").": ";
		$notes2 = mysql_result($notes_result, $m, "note_text");
		$notes_text=$notes_text.'<tr><td valign=top>'.$notes1.'</td><td valign=top>'.$notes2.'</td><tr>';
		$m++;
	}
	
	
		  
		  $quoteTT ="<img src=../images/view.png  width=20 height=16><table id=table_tool_tip width=450 ><tr><td  width=75>Quote no:</td><td width=175>".$qn."</td></tr></tr><tr><td valign=top>Items quoted:</td><td valign=top>".$line_text."</td></tr><tr><td valign=top>Total quote value:</td><td valign=top>P".number_format($a7, 2, '.', ',')."</td></tr><tr><td>Notes:</td><td></td></tr>".$notes_text."</table><br><b>Click for details</b>";
		  ?>
          <a href="quotation.php?quote_no=<?php echo $qn?>" onMouseover="ddrivetip('<?php echo $quoteTT ?>', 450)"; onMouseout="hideddrivetip()"><?php echo "Q".$qn."&nbsp;&nbsp;&nbsp;"; ?> </a>
		  <?php
		  
		  $i++;
	  }
	  ?>

	  </td>
    </tr>
  </table>
</div>
<div class="page_middle_frame">
  <div align="left">Job history</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="131" height="25">Succesfull jobs:</td>
      <td width="535"><?php 
	  $i=0;
	  while ($i<$job_num) {
		  $job_no = mysql_result($job_result, $i, "job_no");
		  $project_no = mysql_result($job_result, $i, "project_no");
		  $project_place = mysql_result($job_result, $i, "project_place");
		  $project_description = mysql_result($job_result, $i, "project_description");
		  $designer = mysql_result($job_result, $i, "designer");
		  $value = mysql_result($job_result, $i, "value");
		  $delivered = mysql_result($job_result, $i, "delivered");
		  if ($delivered == NULL) {$deliver_text = 'Not delivered yet.';}
		  if ($delivered == 'no') {$deliver_text = 'Partly delivered.';}
		  if ($delivered == 'yes') {$deliver_text = 'Fully delivered.';}
		  
		  
		 $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>".$project_no."&nbsp;".$project_place."</td></tr><tr><td>Project description:</td><td>".$project_description."</td></tr><tr><td>Designer:</td><td>".$designer."</td></tr><tr><td>Job value:</td><td>P ".number_format($value, 2, '.', ',')."</td></tr><tr><td>Job completed:</td><td>".$deliver_text."</td></tr><tr></table><br><b>Click for details</b>";
	
		  ?>
        <a href="../production/captured_job.php?job_no=<?php echo $job_no?>" onmouseover="ddrivetip('<?php echo $jobTT ?>', 450)"; onmouseout="hideddrivetip()"><?php echo "J".$job_no."&nbsp;&nbsp;&nbsp;"; ?></a>
        <?php
		  
		  $i++;
	  }
	  ?></td>
    </tr>
  </table>
</div>
<p>&nbsp;</p>

</td>
</tr>
</table>  <!--end of tableMain-->
  
</div>

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

</body>
<?php } else {
$_SESSION['denied_return'] = "sales/sales_main.php";	
include ("../navigation/sales_sidebar.php");?>
	<body onload="accessdenied(); return false">
	</body>
<?php }
?>
</html>