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

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

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

<script type="text/javascript" src="../jscript/tablesort.js"></script>
<?php
include('../include/session.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");
$a19 = mysql_result($customer_result, 0, "account_type");
$a20 = mysql_result($customer_result, 0, "name_2");
$a21 = mysql_result($customer_result, 0, "title");
$a22 = mysql_result($customer_result, 0, "registration_date");

$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']."_compiled_jobs ";
$job_query = "SELECT  job_card_no, project_no, project_place, project_description, value, completed  FROM $table_name WHERE cust_id ='".$cust_id."' ";
$job_result = mySQL_query($job_query);
$job_num = mysql_num_rows($job_result);

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

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

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

<div class="main_frame" style="height:auto;">
  <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>

<div class="page_middle_frame">
<div class="page_inside_frame">
<div align="left">Company details</div>
  <table width="680" id="table_details_display">
    <tr>
      <td height="25">Account:</td>
      <td width="218"><?php echo $a19 ?>&nbsp;</td>
      <td>Registration date:</td>
      <td><?php echo date("d-m-Y", strtotime($a22)) ?></td>
    </tr>
    <tr>
      <td width="148" height="25">Company/surname:</td>
      <td colspan="3"><b><?php echo $a0?> </b> &nbsp;</td>
      </tr>
    <tr>
      <td height="25">First name:</td>
      <td><?php echo $a20 ?>&nbsp;</td>
      <td width="116">Title:</td>
      <td width="178"><?php echo $a21 ?>&nbsp;</td>
    </tr>
  </table>
</div>
</td>
</tr>
<tr>
<td>
<div class="page_inside_frame">
<div align="left">Contact details</div>
  <table width="679" id="table_details_display">
    <tr>
      <td width="141" height="25">Postal address:</td>
      <td width="122"><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_inside_frame">
<div align="left">Company contacts</div>
  <table width="678" id="table_details_display">
    <tr>
      <td width="141" height="25">Contact 1:</td>
      <td width="121"><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_inside_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_inside_frame">
<div align="left">History</div>
<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": [[ 1, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
                             	{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true}
						 ]
				} );
			} );
		</script>

  <table width="678" id="scroll_table" class="data_display">
    <thead>
    <tr>
      <th width="74" height="25">Date</th>
      <th width="33">&nbsp;</th>
      <th>Type</th>
      <th>No</th>
      <th>Project</th>
      </tr>
      </thead>
      <tbody>
      <?php 
	  $i=0;
	  if ($quote_num!=0) {
	  while ($i<$quote_num) {
		  $qn = mysql_result($quote_result, $i, "quote_no");
		  $table_name = $_SESSION['db_prefix']."_quotations";
          $quotation_query = "SELECT  quotation_date, request_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");
		  $qn4 = mysql_result($quotation_result, 0, "request_date");
		  
		  	$table_name = $_SESSION['db_prefix']."_compiled_jobs";
			$job_query = "SELECT job_card_no, date, project, project_no,  project_area, project_place FROM $table_name WHERE job_no = '".$qn."' ";
			$job_result = mySQL_query($job_query);
			$job_num = mysql_num_rows($job_result);
			if ($job_num!=0) {
			$job_card_no = mysql_result($job_result, 0, "job_card_no");
			$job_date = mysql_result($job_result, 0, "date");
			$project = mysql_result($job_result, 0, "project");
			$project_no = mysql_result($job_result, 0, "project_no");
			$project_area = mysql_result($job_result, 0, "project_area");
			$project_place = mysql_result($job_result, 0, "project_place");
						
			$jobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Job card:</td><td width=175>".$job_card_no."</td></tr><tr><td  width=75>Project:</td><td width=175>".$project."</td></tr><tr><td>Project place:</td><td>".$project_no."</td></tr><tr><td>&nbsp;</td><td>".$project_area."</td></tr><tr><td>&nbsp;</td><td>".$project_place."</td></tr></table><br><b>Click for details</b>";
			?>
			<tr>
    			<td><?php echo date("d-m-Y", strtotime($job_date)) ?></td>
    			<td><?php echo $job_date ?></td>
    			<td width="135">Job</td>
    			<td width="96"><?php echo $qn ?>&nbsp;&nbsp;-&nbsp;<a href="../orders/job_card.php?job_card_no=<?php echo $job_card_no ?>" onmouseover="ddrivetip('<?php echo $jobTT ?>', 250)"; onmouseout="hideddrivetip()"><?php echo $job_card_no ?></a></td>
    			<td width="316"><?php echo $project.':&nbsp;&nbsp;'.$project_no.' '.$project_area.' '.$project_place; ?></td>
    		</tr>
	<?php		}


if ($qn1!='0000-00-00') {
		  
	$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="";
	if ($line_num!=0) {
	$products=mysql_result($line_result, 0, "quote_item_text");
	}
	else {
		$products='';
	}
		
	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 ="<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>";

$requestTT = "<table id=table_tool_tip width=250 ><tr><td  width=75>Request no:</td><td width=175>".$qn."</td></tr><tr><td  width=75>Project:</td><td width=175>".$project."</td></tr><tr><td>Project place:</td><td>".$project_no."</td></tr><tr><td>&nbsp;</td><td>".$project_area."</td></tr><tr><td>&nbsp;</td><td>".$project_place."</td></tr></table><br><b>Click for details</b>";

		  ?>
      
    <tr>
    <td><?php echo date("d-m-Y", strtotime($qn1)) ?></td>
    <td><?php echo $qn1 ?></td>
    <td width="135"><a href="quotation.php?quote_no=<?php echo $qn ?>" onMouseover="ddrivetip('<?php echo $quoteTT ?>', 450)"; onMouseout="hideddrivetip()">Quote</a></td>
    <td width="96"><a href="quotation.php?quote_no=<?php echo $qn ?>" onmouseover="ddrivetip('<?php echo $quoteTT ?>', 450)"; onmouseout="hideddrivetip()"><?php echo $qn ?></a></td>
    <td width="316"><?php echo $project.':&nbsp;&nbsp;'.$project_no.' '.$project_area.' '.$project_place; ?></td>
    </tr>
    
    <tr>
    			<td><?php echo date("d-m-Y", strtotime($qn4)) ?></td>
    			<td><?php echo $qn4 ?></td>
    			<td width="135">Request</td>
    			<td width="96"><a href="quotation_request.php?quote_no=<?php echo $qn ?>" onMouseover="ddrivetip('<?php echo $requestTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $qn ?></a></td>
    			<td width="316"><?php echo $project.':&nbsp;&nbsp;'.$project_no.' '.$project_area.' '.$project_place; ?></td>
    		</tr>
    
  <?php
}
		  $i++;
	  }
	  }
  ?>
  
<?php
$table_name = $_SESSION['db_prefix']."_maintenance_quotations";
$maintenance_query = "SELECT quote_no, request_date, project, value  FROM $table_name WHERE cust_id = '".$cust_id."' ";
$maintenance_result = mySQL_query($maintenance_query);
$maintenance_num = mysql_num_rows($maintenance_result);
$m=0;
while ($m<$maintenance_num) {
  $quote_number = mysql_result($maintenance_result, $m, "quote_no");
  $request_date = mysql_result($maintenance_result, $m, "request_date");
  $project = mysql_result($maintenance_result, $m, "project");
  $value = mysql_result($maintenance_result, $m, "value");
    
  
  $mquoteTT ="<table id=table_tool_tip width=450 ><tr><td  width=75>Quote no:</td><td width=175>".$quote_number."</td></tr></tr><tr><td valign=top>Project:</td><td valign=top>".$project."</td></tr><tr><td valign=top>Total quote value:</td><td valign=top>P".number_format($value, 2, '.', ',')."</td></tr></table><br><b>Click for details</b>";
?>
<tr>
      <td><?php echo date("d-m-Y", strtotime($request_date)) ?></td>
      <td><?php echo $request_date ?></td>
      <td>Maintenance quote</td>
      <td><a href="../maintenance/maintenance_quotation.php?quote_no=<?php echo $quote_number ?>" onMouseover="ddrivetip('<?php echo $mquoteTT ?>', 350)"; onMouseout="hideddrivetip()"><?php echo $quote_number ?></a></td>
      <td><?php echo $project ?></td>
    </tr>
<?php 
$m++;
}
?>

<?php
$table_name = $_SESSION['db_prefix']."_maintenance_jobs";
$maintenance_job_query = "SELECT maintenance_no, maintenance_card_no, completion_date, project, project_no, project_area, project_place FROM $table_name WHERE cust_id = '".$cust_id."' ";
$maintenance_job_result = mySQL_query($maintenance_job_query);
$maintenance_job_num = mysql_num_rows($maintenance_job_result);
$n=0;
while ($n<$maintenance_job_num) {
  $maintenance_no = mysql_result($maintenance_job_result, $n, "maintenance_no");
  $maintenance_card_no = mysql_result($maintenance_job_result, $n, "maintenance_card_no");
  $completion_date = mysql_result($maintenance_job_result, $n, "completion_date");
  $project = mysql_result($maintenance_job_result, $n, "project");
  $project_no = mysql_result($maintenance_job_result, $n, "project_no");
  $project_area = mysql_result($maintenance_job_result, $n, "project_area");
  $project_place = mysql_result($maintenance_job_result, $n, "project_place");
  
  
$mjobTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Job card:</td><td width=175>".$maintenance_card_no."</td></tr><tr><td  width=75>Project:</td><td width=175>".$project."</td></tr><tr><td>Project place:</td><td>".$project_no."</td></tr><tr><td>&nbsp;</td><td>".$project_area."</td></tr><tr><td>&nbsp;</td><td>".$project_place."</td></tr></table><br><b>Click for details</b>";
?>
<tr>
      <td><?php echo date("d-m-Y", strtotime($completion_date)) ?></td>
      <td><?php echo $completion_date ?></td>
      <td>Maintenance job</td>
      <td><?php echo $maintenance_no ?>&nbsp;&nbsp;-&nbsp;<a href="../maintenance/maintenance_card.php?maintenance_card_no=<?php echo $maintenance_card_no ?>" onMouseover="ddrivetip('<?php echo $mjobTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $maintenance_card_no ?></a></td>
      <td><?php echo $project ?></td>
    </tr>
<?php 
$n++;
}
?>
	
	</tbody>  
  </table>
</div></div>
  
</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>