<!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']."_quotations";
$quote_query = "SELECT  quote_no, project_no, project_place, project_description, seller, quote_value, quotation_date  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']."_tile_orders";
$order_query = "SELECT  order_no, direct, value, order_date  FROM $table_name WHERE cust_id ='".$cust_id."' ";
$order_result = mySQL_query($order_query);
$order_num = mysql_num_rows($order_result);

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

<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<body>


<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;
	  $quoteTT_line = '';
	  
	  while ($i<$quote_num) {
		  $a1 = mysql_result($quote_result, $i, "quote_no");
		  $table_name = $_SESSION['db_prefix']."_quotations";
          $quotation_query = "SELECT  quotation_date, project_no, project_place, project_description, quote_value FROM $table_name WHERE quote_no= '".$a1."' ";
		  $quotation_result = mySQL_query($quotation_query);
		  $a4 = mysql_result($quotation_result, 0, "project_no");
		  $a5 = mysql_result($quotation_result, 0, "project_place");
		  $a6 = mysql_result($quotation_result, 0, "project_description");
		  $a7 = mysql_result($quotation_result, 0, "quote_value");
          
		  
	
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
		$notes_query = "SELECT note_date, note_text FROM $table_name WHERE quote_number = '".$a1."' ";
		$notes_result = mySQL_query($notes_query);
		$notes_num = mysql_num_rows($notes_result);
		$j=0;
		while ($j<$notes_num) {
		$note_date = mysql_result($notes_result, $j, "note_date");
		$note_text = mysql_result($notes_result, $j, "note_text"); 	
		$quoteTT_line = $quoteTT_line.'<tr><td>'.date("d-m-Y", strtotime($note_date)).'</td><td>'.$note_text.'</td><tr>';
		$j++;	
		}
	
	
		  
		$quoteTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Quote no:</td><td width=175>".$a1."</td></tr><tr><td valign=top>Project no /place:</td><td>".$a4."&nbsp;".$a5."</td></tr><tr><td>Project description:</td><td>".$a6."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>Sales rep:</td><td>&nbsp;</td></tr><tr><td>Value:</td><td>".$a7."</td></tr><tr><td>Notes:</td><td>&nbsp;</td></tr>".$quoteTT_line."</table><br><b>Click for details</b>";	
		  ?>
          
          <a href="quotation.php?quote_no=<?php echo $a1?>" onMouseover="ddrivetip('<?php echo $quoteTT ?>', 450)"; onMouseout="hideddrivetip()"><?php echo "Q".$a1?> </a>&nbsp;&nbsp;&nbsp; 
		  <?php
		  
		  $i++;
	  }
	  ?>

	  </td>
    </tr>
  </table>
</div>
<div class="page_middle_frame">
  <div align="left">Order history</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="131" height="25">Succesfull orders:</td>
      <td width="535">
	  <?php 
	  
	  $i=0;
	  $orderTT_line = '';
	  while ($i<$order_num) {
		  $a1 = mysql_result($order_result, $i, "order_no");
		  $table_name = $_SESSION['db_prefix']."_quotations";
          $quotation_query = "SELECT  quotation_date, project_no, project_place, project_description, quote_value FROM $table_name WHERE quote_no= '".$a1."' ";
		  $quotation_result = mySQL_query($quotation_query);
		  $a4 = mysql_result($quotation_result, 0, "project_no");
		  $a5 = mysql_result($quotation_result, 0, "project_place");
		  $a6 = mysql_result($quotation_result, 0, "project_description");
		  
		  
		  $a7 = mysql_result($order_result, 0, "value");
 
		  
		$orderTT ="<table id=table_tool_tip width=300 ><tr><td  width=100>Quote no:</td><td width=175>".$a1."</td></tr><tr><td valign=top>Project no /place:</td><td>".$a4."&nbsp;".$a5."</td></tr><tr><td>Project description:</td><td>".$a6."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>Sales rep:</td><td>&nbsp;</td></tr><tr><td>Value:</td><td>".$a7."</td></tr></table><br><b>Click for details</b>";	
	
		  ?>
        <a href="../sales/tile_order_display.php?order_no=<?php echo $a1 ?>" onmouseover="ddrivetip('<?php echo $orderTT ?>', 450)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a>&nbsp;&nbsp;&nbsp;
        <?php
		  
		  $i++;
	  }
	  ?></td>
    </tr>
  </table>
</div>
<br />
<div class="page_middle_frame">
  <div align="left">Item history</div>
  <table width="678" id="table_details_display">
    <tr>
      <td height="25">Click <a href="customer_ordered_list.php?cust_id=<?php echo $cust_id ?>&date=">here</a> for detailed item overview.</td>
      </tr>
  </table>
</div>

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

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

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