<?php
$page_name = "Quote-status";
include ("../navigation/access.php");

if ($permission_num==1) {

$table_name = $_SESSION['db_prefix']."_quotations";
$quote_query = "SELECT quote_no, cust_id, quotation_date, project, project_no, project_place, project_description, value, seller, priority, followup_date FROM $table_name WHERE  status = 'quoted' ORDER BY quote_no DESC ";
$quote_result = mySQL_query($quote_query);
$quote_num = mysql_num_rows($quote_result);
?>
<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />
<link rel="stylesheet" type="text/css" href="../css/scroll_table.css" />

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

<?php include('../include/wait.php') ?>

<body onLoad="MM_showHideLayers('wait','','hide')" onFocus="MM_showHideLayers('wait','','hide');">
<?php include ('../include/tooltip.php'); ?>
<div class="wizard_page_middle_frame">
<div align="right">
    <label class="label_end">&nbsp;&nbsp;<img src="../images/flame_red.png" width="16" height="16" />: hot&nbsp;&nbsp;<img src="../images/flame_orange.png" width="16" height="16" />: Warm&nbsp;&nbsp;<img src="../images/flame_blue.png" width="16" height="16" />: cold</label>
&nbsp;&nbsp;

  </div>
<form id="form1" name="form1" method="get" action="quote_updateWizbase.php">
     <label class="label_std">Select quotation:
          &nbsp;&nbsp;(click on quote number to continue)</label>
      <div class="wizard_frame">
      <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": "300px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 7},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"bSortable": true},
								{"iDataSort": 8},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
          <table width="890" class="data_display" id="scroll_table" >
            <thead>
            <tr>
              <th width="35"align="center" >&nbsp; </th>
              <th width="107" align="center" >Quote no</th>
              <th width="96" align="center" >Quote date</th>
              <th width="156" align="center" >Project</th>
              <th width="134" align="center" >Customer</th>
              <th width="74" align="center" >Value</th>
              <th width="78" align="center" >Last follow-up</th>
              <th width="83" align="center">&nbsp;</th>
              <th width="87" align="center">&nbsp;</th>
            </tr>
            </thead>
            <?php 
	$i=0;
	while ($i<$quote_num) {
		$a1 = mysql_result($quote_result, $i, "quote_no");
		
		$a2 = mysql_result($quote_result, $i, "cust_id");
		if ($a2!=0) {
			$table_name = $_SESSION['db_prefix']."_customer";
			$customer_query = "SELECT status, comp_name, bag_box, box_no, postal_place, phone, contact_1  FROM $table_name WHERE cust_id = '".$a2."' ";
			$customer_result = mySQL_query($customer_query);
			$customer_num = mysql_num_rows($customer_result);
			$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");
			$a2g = mysql_result($customer_result, 0, "status");
			}
		else
	 {
		    $a2a = 'Bill of quantity';
			$a2b = '';
			$a2c = '';
			$a2d = '';
			$a2e = '';
			$a2f = '';
			$a2g = '';
	 }
		
			
		 $a3 = mysql_result($quote_result, $i, "quotation_date");
		 $a4 = mysql_result($quote_result, $i, "project_no");
		 $a5 = mysql_result($quote_result, $i, "project_place");
		 $a6 = mysql_result($quote_result, $i, "project_description");
		 $a7 = mysql_result($quote_result, $i, "value");
		 $a8 = mysql_result($quote_result, $i, "project");
		 $a9 = mysql_result($quote_result, $i, "seller");
		 $a10 = mysql_result($quote_result, $i, "priority");
		 $a11 = mysql_result($quote_result, $i, "followup_date");
	
	
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$line_query = "SELECT  quote_item_text, quote_item_price   FROM $table_name WHERE quote_number = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	$l=0;
	
	$line_text="";
		 
		while($l<$line_num) {
	   $price=mysql_result($line_result, $l, "quote_item_price");
	   
	  
	   $line = mysql_result($line_result, $l, "quote_item_text");
	   $line_text = $line_text."&nbsp;-&nbsp;".$line." @ P ".number_format($price, 2, '.', ',')."<br>";
	   $l++;
	   
	}
	
	//$a7tot = $a7tot + $a7;
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$a1."' 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++;
	}
		 	
	if ($a2==0) {
		$customerTT = 'Bill of quantity';
	}
	else {
		$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>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>Project</td><td>".$a8."</td></tr><tr><td>Sales assistant:</td><td>".$a9."</td></tr><td>Value:</td><td>".$a7."</td></tr></table><br><b>Click for details</b>";
		
		$quoteTT ="<table id=table_tool_tip width=450 ><tr><td  width=75>Quote no:</td><td width=175>".$a1."</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>".$notes_text."</td></tr></table><br><b>Click for details</b>";
		
		if ($notes_text!='') { 
		        $followupTT ="<table id=table_tool_tip width=450 ><tr><td width=150>".$notes_text."</td></tr></table>";
		}
		else {
			 $followupTT ="<table id=table_tool_tip width=450 ><tr><td width=150>No follow up notes.</td></tr></table>";
		}
	
	?>
            <tr>
              <td align="center">
              <?php if ($a10=="Hot") { ?>
                <img src="../images/flame_red.png" width="16" height="16"  />
                <?php } ?>
              <?php if ($a10=="Warm") { ?>
                <img src="../images/flame_orange.png" width="16" height="16"  />
                <?php } ?>
              <?php if ($a10=="Cold") { ?>
                <img src="../images/flame_blue.png" width="16" height="16"  />
                <?php } ?></td>
              <td style="padding-left:0>x"><a href="quote_updateWizbase.php?quote_no=<?php echo $a1?>&cust_id=<?php echo $a2 ?>&p=2&s=1" onMouseover="ddrivetip('<?php echo $quoteTT ?>', 500)"; onMouseout="hideddrivetip()" onClick="needToConfirm = false; MM_showHideLayers('wait','','show');"><?php if ($a2==0) {echo '<font color=#209949>'.$a1.'</font>';} else { echo $a1; }?></a></td>
              <td><?php echo date("d-m-Y", strtotime($a3)) ?></td>
              <td><?php echo $a8 ?></td>
              <td><a href="" onMouseover="ddrivetip('<?php echo $customerTT ?>', 250)"; onMouseout="hideddrivetip()"><?php echo $a2a?></a></td>
              <td align="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
              <td align="left"><?php if ($notes_text!='') { ?> <a href=" " onMouseover="ddrivetip('<?php echo $followupTT ?>', 450)"; onMouseout="hideddrivetip()"><?php echo date("d-m-Y", strtotime($a11));  ?></a> <?php } else { echo 'n/a'; } ?></td>
              <td><?php echo $a3 ?></td>
              <td><?php echo $a11 ?></td>
            </tr>
            <?php 
	$i++;
	}
	?>
          </table>
          <br>
        </div>
        <div class="wizard_frame">
        <table width="675" height="50" align="center" id="table_button_bar">
          <tr>
            <td width="117">&nbsp;</td>
            <td width="115"><input name="p" type="hidden" id="p" value="1" />
              <input name="error" type="hidden" id="error" value="0" />
              <input name="s" type="hidden" id="s" value="1" /></td>
            <td width="99">&nbsp;</td>
            <td width="125"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onClick="needToConfirm = false; cancel_confirmation(1, '../sales/sales_main.php?date='); " value="Cancel" /></td>
            <td width="110" align="right">&nbsp;</td>
          </tr>
        </table>
        </div>
</form>
</div>
</body>
<?php } else { 
    $_SESSION['denied_return'] = "sales/sales_main.php?date=";	?>
<body onLoad="needToConfirm = false; accessdenied(); return false">
</body>
<?php }
?>
