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

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

<?php
include('../include/period_select_date.php');


$table_name2 = $_SESSION['db_prefix']."_quotations";
$quotation_query = "SELECT quote_no,  cust_id, cust_type, quote_type, seller, quotation_date, deliver_date, company_contact, contact_phone, project_no, project_place, quote_value, status, branch, quote_discount, quote_vat, transport, pallets, pallets_price FROM $table_name2 WHERE branch = 'Gaborone' AND quotation_date BETWEEN '".$start."' AND '".$end."' ORDER BY quote_no DESC ";
$quotation_result = mySQL_query($quotation_query);
$quotation_num = mysql_num_rows($quotation_result);	
?>

<div class="page_middle_frame" style="height:690px;"> 

<ul class="tabs">
      <li>
          <input type="radio" checked  name="tabs" id="tab1">
          <label class="tab" for="tab1"><a class="tabs" href="quotations_list.php?branch=Gaborone&date=">Gaborone</a></label>
<div id="tab-content1" class="tab-content animated fadeIn" style="height:630px;">    
<form action="quotations_list.php" method="get" name="dateform" class="today" id="dateform">
<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": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"bSortable": true},
                             	{"bSortable": true},
								{"iDataSort": 11},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
								{"bSortable": true},
                              	{"bSortable": true},
                             	{"bSortable": true},
								{"iDataSort": 12},
								{"bSortable": true},
								{"bVisible": false},
								{"bVisible": false}
								 ]
				} );
			} );
		</script>
       
        
        
         <?php
$page='quotations_list.php';
$reference_name='branch';
$reference='Gaborone';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>
        </form>
       
        
        
          <div align="right">
            <label class="label_end"><img src="../images/round_green.png" width="8" height="8" />: succes&nbsp;&nbsp;<img src="../images/round_orange.png" width="8" height="8" />: pending&nbsp;&nbsp;<img src="../images/round_red.png" width="8" height="8" />:unsuccesful</label>
          </div>
          <table width="700" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th align="center" >&nbsp;</th>
              <th width="15" style="border-right-style:hidden;">&nbsp;</th>
              <th width="62" >Number</th>
              <th >Quote Date</th>
              <th >Branch</th>
              <th >Type</th>
              <th >Project no</th>
              <th >Name</th>
              <th >Contact</th>
              <th >Value</th>
              <th >Sales rep.</th>
              <th>&nbsp;</th>
              <th>&nbsp;</th>
            </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
while ($i<$quotation_num) {
	$a1 = mysql_result($quotation_result, $i, "quote_no");
		
	     $a2 = mysql_result($quotation_result, $i, "cust_id");
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = mySQL_query($customer_query);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $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");
		 $a3 = mysql_result($customer_result, 0, "status");
		 
		 }
	
	
	$a5 = mysql_result($quotation_result, $i, "quotation_date");
	//$a6 = mysql_result($quotation_result, $i, "required_date");
		
	$a7 = mysql_result($quotation_result, $i, "quote_value");
	$a8 = mysql_result($quotation_result, $i, "seller");
	$a9 = mysql_result($quotation_result, $i, "company_contact");
	$a10 = mysql_result($quotation_result, $i, "contact_phone");
	$a11 = mysql_result($quotation_result, $i, "status");
	$a12 = mysql_result($quotation_result, $i, "project_no");
	$a15 = mysql_result($quotation_result, $i, "project_place");
	$a13 = mysql_result($quotation_result, $i, "quote_type");
	$quote_discount = mysql_result($quotation_result, $i, "quote_discount");
	$quote_vat = mysql_result($quotation_result, $i, "quote_vat");
	$transport = mysql_result($quotation_result, $i, "transport");
	$pallets = mysql_result($quotation_result, $i, "pallets");
	$pallets_price = mysql_result($quotation_result, $i, "pallets_price");
	
	$pallets_total = $pallets_price * $pallets;
	
	
	$a14 = mysql_result($quotation_result, $i, "branch");
	
	if ($a13=='tiles') {
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$line_query = "SELECT  store_item_id, quantity, price   FROM $table_name WHERE quote_no = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	
	$l=0;
	$total=0;
	$line_text="";
	$products=mysql_result($line_result, 0, "store_item_id");
		
	while($l<$line_num) {
		$store_item_id = mysql_result($line_result, $l, "store_item_id");
		$quantity = mysql_result($line_result, $l, "quantity");
		$price = mysql_result($line_result, $l, "price");
		
		
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
		$name_result = mySQL_query($name_query);
		$store_item_name = mysql_result($name_result, 0, "item_name");
		$sub_total =  $quantity * $price;
		$total = $total + $sub_total;
			  
	   	$line_text = $line_text."<tr><td>".$store_item_name."</td><td>".$quantity."</td><td align=right>".number_format($price, 2, '.', ',')."</td><td align=right>".number_format($sub_total, 2, '.', ',')."</td></tr>";
	   $l++;
	}
	$discount = $total * ($quote_discount/100);
	$sub_total = $total - $discount;
	$sub_total3 = $sub_total + $transport + $pallets_total;
	$vat = $sub_total3 * ($quote_vat/100); 
	$all_total = $sub_total3 + $vat;
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$a1."' ORDER BY line_id 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>Item</td><td>Quantity</td><td align=center>Price</td><td align=center>Total</td></tr>".$line_text."<tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total:</td><td align=right>".number_format($total, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Discount: ".$quote_discount."%</td><td align=right>".number_format($discount, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total:</td><td align=right>".number_format($sub_total, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>".$pallets." pallets: </td><td align=right>".number_format($pallets_total, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Transport: </td><td align=right>".number_format($transport, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total: </td><td align=right>".number_format($sub_total3, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>VAT: ".$quote_vat."%</td><td align=right>".number_format($vat, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Total:</td><td align=right>".number_format($all_total, 2, '.', ',')."</td></tr></table><br><table><tr><td>Notes:</td><td></td></tr>".$notes_text."</table><br><b>Click for details</b>";
	}
	
	if ($a13=='trusses') {
	$table_name = $_SESSION['db_prefix']."_quotation_lines";
	$line_query = "SELECT  truss_item, quantity, price FROM $table_name WHERE quote_no = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	$l=0;
	$total=0;
	$line_text="";
	
		
	while($l<$line_num) {
	   $truss_item=mysql_result($line_result, $l, "truss_item");	
	   $quantity=mysql_result($line_result, $l, "quantity");
	   $price=mysql_result($line_result, $l, "price");
	   
	   $transport = mysql_result($quotation_result, $i, "transport");
	   
	   $sub_total =  $quantity * $price;
	   $total = $total + $sub_total;
	     
	   
	   $line_text = $line_text."<tr><td>".$truss_item."</td><td align=right>".$quantity."</td><td align=right>".number_format($price, 2, '.', ',')."</td><td align=right>".number_format($sub_total, 2, '.', ',')."</td></tr>";
	   $l++;
	}
	$discount = $total * ($quote_discount/100);
	$sub_total = $total - $discount;
	$sub_total2 = $sub_total + $transport;
	$vat = $sub_total2 * ($quote_vat/100); 
	$all_total = $sub_total2 + $vat;
	
	$table_name = $_SESSION['db_prefix']."_quotation_notes";
	$notes_query = "SELECT  note_date, note_text, seller   FROM $table_name WHERE quote_number = '".$a1."' ORDER BY line_id 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>Item</td><td>Quantity</td><td align=center>Price</td><td align=center>Total</td></tr>".$line_text."<tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total:</td><td align=right>".number_format($total, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Discount: ".$quote_discount."%</td><td align=right>".number_format($discount, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total:</td><td align=right>".number_format($sub_total, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Transport:</td><td align=right>".number_format($transport, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Sub total:</td><td align=right>".number_format($sub_total2, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>VAT: ".$quote_vat."%</td><td align=right>".number_format($vat, 2, '.', ',')."</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td align=right>Total:</td><td align=right>".number_format($all_total, 2, '.', ',')."</td></tr></table><br><table><tr><td>Notes:</td><td></td></tr>".$notes_text."</table><br><b>Click for details</b>";
	}
	
	$a7tot = $a7tot + $a7;
	
	
	
	if ($a13=='tiles') { $a13 = 'Tiles & Acc.';}
	if ($a13=='trusses') { $a13 = 'Installation';}
	
		
    $productsTT ="";
//	$productsTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Products quoted:</td><td width=175>".$line_text."</td></tr></table><br><b>Click for details</b>";
	
	$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>";
	?>
            <tr>
              <td align="center"><?php if ($a11=="quoted") { ?>
                <img src="../images/round_orange.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="successful") { ?>
                <img src="../images/round_green.png" width="12" height="12"  />
                <?php } ?>
                <?php if ($a11=="unsuccessful") { ?>
                <img src="../images/round_red.png" width="12" height="12"   />
                <?php } ?></td>
              <td align="left" style="border-right-style:hidden; padding-right:0px" >Q</td>
              <td align="left"  style="padding-left:0px;"><a href="quotation.php?quote_no=<?php echo $a1 ?>&authorise=0" onmouseover="ddrivetip('<?php echo $quoteTT?>', 450)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td align="left"><?php echo $a14 ?></td>
              <td align="left"><?php echo $a13 ?></td>
              <td align="left"><?php echo $a12.'<br>'.$a15; ?>&nbsp;</td>
              <td align="left"><a href="customer_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td align="left"><?php echo $a9."<br>".$a10 ?>&nbsp;</td>
              
              <td align="right"><?php echo number_format($a7, 2, '.', ',') ?></td>
              <td align="left"><?php echo $a8 ?>&nbsp;</td>
              <td align="left"><?php echo $a5 ?>&nbsp;</td>
              <td align="left"><?php echo $a7 ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
              <tr>
                <td colspan="8" align="right" valign="bottom">Total:</td>
                <td colspan="2" align="right" valign="bottom"><?php echo number_format($a7tot, 2, '.', ',') ?></td>
                <td colspan="3" valign="bottom">&nbsp;</td>
              </tr>
            </tfoot>
          </table>
 
 </div>
 
 </li>
        <li>
          <input type="radio" name="tabs" id="tab2">
          <label  class="tab" for="tab2"><a class="tabs" href="quotations_list.php?branch=Francistown&date=">Francistown</a></label>
<div id="tab-content2" class="tab-content animated fadeIn">
</div>
        </li>
        <li>
          <input type="radio" name="tabs" id="tab3">
          <label class="tab"for="tab3"><a class="tabs" href="quotations_list.php?branch=Combined&date=">Combined</a></label>
           
 <div id="tab-content3" class="tab-content animated fadeIn">
 
          </div>
        </li>
</ul>
 
  </div>


 

