<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include ("../navigation/header.php");
$page_name = "Sales-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
	
$quote_no = $_GET['quote_no'];
	
$table_name = $_SESSION['db_prefix']."_quotations";
$quotation_query = "SELECT cust_id, deliver_date, quotation_date, seller, project_no, project_place, project_description, company_contact, contact_phone  FROM $table_name WHERE quote_no = '".$quote_no."' ";
$quotation_result = mySQL_query($quotation_query);
$seller = mysql_result($quotation_result, 0, "seller");
$cust_id = mysql_result($quotation_result, 0, "cust_id");
$deliver_date = mysql_result($quotation_result, 0, "deliver_date");
$quote_date = mysql_result($quotation_result, 0, "quotation_date");
$project_no = mysql_result($quotation_result, 0, "project_no");
$project_place = mysql_result($quotation_result, 0, "project_place");
$project_description = mysql_result($quotation_result, 0, "project_description");
$company_contact = mysql_result($quotation_result, 0, "company_contact");
$contact_phone = mysql_result($quotation_result, 0, "contact_phone");

	
$table_name = $_SESSION['db_prefix']."_quotation_lines";
$line_query = "SELECT *  FROM $table_name WHERE  quote_no =  '".$quote_no."'";
$line_result = mySQL_query($line_query);
$line_num = mysql_num_rows($line_result);



	$table_name = $_SESSION['db_prefix']."_customer";
    $customer_query = "SELECT comp_name, bag_box, box_no, postal_place, phone, contact_1, email_1   FROM $table_name WHERE cust_id = '".$cust_id."' ";
	$customer_result = mySQL_query($customer_query);
	
    $b1 = mysql_result($customer_result, 0, "comp_name");
	$b2 = mysql_result($customer_result, 0, "bag_box");
	$b3 = mysql_result($customer_result, 0, "box_no");
	$b4 = mysql_result($customer_result, 0, "postal_place");
	$b5 = mysql_result($customer_result, 0, "phone");
	$b6 = mysql_result($customer_result, 0, "contact_1");
	$b7 = mysql_result($customer_result, 0, "email_1");

?>

</head>
<body>
<div class="main_frame" style="height:auto;"><!--end of tableMain-->
<div class="page_head_frame">
  <label class="label_page_head">Quotation</label>&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $quote_no.' '.$b1 ?></label></div>
<div class="page_middle_frame">
             Quotation details:
               <table width="670" id="table_details_display">
                <tr>
                  <td width="123">Sales representative:</td>
                  <td width="205"><?php echo $seller ?></td>
                  <td width="109">Delivery date:</td>
                  <td width="213"><?php echo date("d-m-Y", strtotime($deliver_date)) ?></td>
                </tr>
              </table>
            
            <br />


             Quotation for:
            
              <table width="670" id="table_details_display">
                <tr>
                  <td width="123">Name:</td>
                  <td colspan="3"><?php echo  $b1 ?></td>
                </tr>
                <tr>
                  <td>Contact person:</td>
                  <td width="205"><?php echo $company_contact ?></td>
                  <td width="109">Phone/cell:</td>
                  <td width="213"><?php echo $contact_phone ?></td>
                </tr><br />


                <tr>
                  <td>Address:</td>
                  <td colspan="3"><?php echo $b2." ".$b3.", ".$b4?></td>
                </tr>
                <tr>
                  <td>Telephone:</td>
                  <td><?php echo $b5 ?></td>
                  <td>e-mail:</td>
                  <td><?php echo $b7 ?></td>
                </tr>
              </table>
            
<br />
               Quotation details:
                <table width="670" id="table_details_display">
                  <tr>
                    <td width="123">Quotation date:</td>
                    <td colspan="3"><strong><span class="wizard"><?php echo date("d-m-Y", strtotime($_SESSION['receive_date'])) ?></span></strong></td>
                  </tr>
                  <tr>
                    <td>Project no:</td>
                    <td width="177"><?php echo $project_no?></td>
                    <td width="58">Place:</td>
                    <td width="292"><?php echo $project_place ?></td>
                  </tr>
                  <tr>
                    <td>Project description:</td>
                    <td colspan="3"><?php echo $project_description ?></td>
                  </tr>
                </table>
              
              <br>
              <table width="670" id="table_display" >
                <tr>
                  <td height="26" colspan="2" align="left" valign="top">Item</td>
                  <td width="116" align="left" valign="top">Group</td>
                  <td width="71" align="left" valign="top">Unit</td>
                  <td width="56" align="left" valign="top">quantity</td>
                  <td width="85" align="left" valign="top">price</td>
                  <td width="73" align="left" valign="top">total</td>
                </tr>
                <?php
				$i=0;
				$sub_tot=0;
				$a5_total=0;
				 while ($i<$line_num){
					 $a0 = mysql_result($line_result, $i, "quote_no");
					 $a1 = mysql_result($line_result, $i, "store_item_id");
					 $table_name = $_SESSION['db_prefix']."_store_items";
						$item_query = "SELECT item_name, unit, subCategory FROM $table_name WHERE store_item_id = '".$a1."' ";
						$item_result = mySQL_query($item_query);
						$a1a = mysql_result($item_result, 0, "item_name");
						$a3a = mysql_result($item_result, 0, "unit");
						$a4a = mysql_result($item_result, 0, "subCategory");
					 $a2 = mysql_result($line_result, $i, "quantity");
					 $a3 = mysql_result($line_result, $i, "price");
					 
					$a5=$a2*$a3;
					$a5_total=$a5_total+$a5;
					 
				 ?>
                <tr>
                  <td colspan="2" valign="top"><?php echo $a1a ?></td>
                  <td valign="top"><?php echo $a4a ?></td>
                  <td valign="top"><?php echo $a3a ?></td>
                  <td valign="top"><?php echo $a2 ?></td>
                  <td align="right" valign="top"><?php echo $a3. "  /" .$a3a ?>&nbsp;</td>
                  <td align="right" valign="top"><?php echo number_format($a5, 2, '.', ',')?></td>
                </tr>
                <?php 
			   // $a6_total=$a6_total+$a6;
				$i++;
				 }
				 ?>
                <tr>
                  <td colspan="2" align="left" valign="top">&nbsp;</td>
                  <td align="left" valign="top">&nbsp;</td>
                  <td align="left" valign="top">&nbsp;</td>
                  <td align="left" valign="top">&nbsp;</td>
                  <td align="left" valign="top">Total:</td>
                  <td align="right" valign="top"><?php echo number_format($a5_total, 2, '.', ',') ?></td>
                </tr>
              </table>
  
</div>
</div>

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

</body>
<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
$_SESSION['denied_return'] = "store/store_main.php";	
include ("../navigation/store_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>
</html>