<!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 = "Quote-edit";
include ("../navigation/access.php");

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

?>
</head>
<?php

date_default_timezone_set('Africa/Khartoum');
$entry_date = date("Y-m-d H:i:s",time()-3600); 
	
$quote_no = $_GET['quote_no'];


$table_name = $_SESSION['db_prefix']."_quotations";
$quote_query = "SELECT  cust_id, request_date, project_no, project_description, project_place, company_contact, contact_phone, seller, designer  FROM $table_name WHERE  quote_no = '".$quote_no."' ";
$quote_result = mySQL_query($quote_query);
$a1 = mysql_result($quote_result, 0, "cust_id");
$a2 = mysql_result($quote_result, 0, "request_date");
$a3 = mysql_result($quote_result, 0, "project_no");
$a4 = mysql_result($quote_result, 0, "project_description");
$a5 = mysql_result($quote_result, 0, "company_contact");
$a6 = mysql_result($quote_result, 0, "contact_phone");
$a7 = mysql_result($quote_result, 0, "project_place");
$_SESSION['designer'] = mysql_result($quote_result, 0, "designer");
$_SESSION['seller'] = mysql_result($quote_result, 0, "seller");	


$table_name = $_SESSION['db_prefix']."_quotation_lines";
$lines_query = "SELECT * FROM $table_name WHERE quote_number = '".$quote_no."' ";
$lines_result = mySQL_query($lines_query);
$lines_num = mysql_num_rows($lines_result);


$table_name = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT account_type, status, comp_name,name_2, title, bag_box, box_no, postal_place, phone, cell_1  FROM $table_name WHERE cust_id = '".$a1."' ";
$customer_result = mySQL_query($customer_query);
$b0 = mysql_result($customer_result, 0, "account_type");
if ($b0=="corporate") { $b1 = mysql_result($customer_result, 0, "comp_name"); } else { $b1 = mysql_result($customer_result, 0, "title")." ".mysql_result($customer_result, 0, "name_2")." ".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, "cell_1");
$b7 = mysql_result($customer_result, 0, "status");



?>
<link href="../css/main.css" rel="stylesheet" type="text/css">
</head>

<body> <br />

<div class="main_frame">

     
    <div class="page_head_frame">
        
        <table width="809" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="463"><label class="label_page_head">Edit quotation details</label></td>
            <td width="217"><label style="font-size:24px; color:#FB6808;"><?php echo "Q".$quote_no ?></label>&nbsp;</td>
            </tr>
        </table>
      </div><br />

<form id="feedbackform" method="post" action="quotation_details_edit_save.php">
<div class="page_middle_frame"><br />
<br />

            <div class="button_inside_frame">
            <table width="666" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="112" height="29"><label class="label_std">Quote no: </label></td>
                <td width="184">Q<?php echo $quote_no;?></td>
                <td><label class="label_std">Date: </label></td>
                <td><?php  echo date("d-m-Y", strtotime($a2)) ?></td>
              </tr>
              <tr>
                <td height="29"><label class="label_std">Project no:&nbsp;</label></td>
                <td height="29"><?php echo $a3 ?></td>
                <td width="114"><label class="label_std">Customer:</label></td>
                <td width="256"><?php echo $b1?></td>
              </tr>
              <tr>
                <td valign="top"><label class="label_std">Place:</label></td>
                <td valign="top"><?php echo $a7 ?></td>
                <td height="22" valign="top"><label class="label_std">Contact:</label></td>
                <td valign="top"><?php echo $a5?></td>
              </tr>
              <tr>
                <td valign="top"><label class="label_std">Description:</label></td>
                <td valign="top"><?php echo $a4 ?></td>
                <td height="26" valign="top"><label class="label_std">Cell/phone:</label></td>
                <td valign="top"><?php echo $a6?></td>
              </tr>
            </table>
            <label class="label_std"><br>
            </label>
            </div>
            <br>
</div>
<div class="page_middle_frame">
            <div class="button_inside_frame">
            <table  id="table_resume" width="600" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><label class="label_std">Products to quote:&nbsp;&nbsp;</label></td>
                <td align="left" valign="bottom"><label class="label_std">Price (excl VAT)</label></td>
              </tr>
              <?php
			  $i=0;
			  
			  while ($i<3) {
				  if ($i<$lines_num) {
				  $d1 = mysql_result($lines_result, $i, "line_id");
				  $d2 = mysql_result($lines_result, $i, "quote_item_text");
				  $d3 = mysql_result($lines_result, $i, "quote_item_price");
			   ?>
              <tr>
                <td width="334" height="51"><textarea name="quote_line_text<?php echo $i?>" cols="60" rows="2" class="text_box" id="quote_line_text<?php echo $i?>" ><?php echo $d2 ?></textarea></td>
                <td width="315" align="right" valign="bottom"><input type="text" name="quote_price_text<?php echo $i?>" id="quote_price_text<?php echo $i?>" style="text-align:right" value="<?php echo $d3 ?>" onKeyPress="return isNumberKey(event)" ></td>
              </tr>
			 <?php
			  }
			  else {
				  $d1 = '';
				  $d2 = '';
				  $d3 = '';
			  ?>
              <tr>
                <td width="334" height="51"><textarea name="quote_line_text<?php echo $i?>" cols="60" rows="2" class="text_box" id="quote_line_text<?php echo $i?>" ><?php echo $d2 ?></textarea></td>
                <td width="315" align="right" valign="bottom"><input type="text" name="quote_price_text<?php echo $i?>" id="quote_price_text<?php echo $i?>" style="text-align:right" value="<?php echo $d3 ?>" onKeyPress="return isNumberKey(event)" ></td>
              </tr>
              <?php
			  }
				$i++;
			  }
			  ?>
            </table>
            <br>
      </div>
            

<br />
</div>
<div class="page_middle_frame">
  <table width="645" border="0">
    <tr>
      <td width="20"></td>
      <td width="615" align="right"><input type="hidden" name="cust_id_text" id="cust_id_text" value="<?php echo $a1 ?>" />
        <input type="hidden" name="quote_no_text" id="quote_no_text" value="<?php echo $quote_no ?>" />
        <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../sales/sales_main.php?date=0');" value="Close"/>
        <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onclick="needToConfirm = false; confirmRefresh();" />
        <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; confirmRefresh();" /></td>
    </tr>
  </table>
</div>
</form>

<!--form validation-->
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  //frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("quote_line_1_text","req","At least one item is required. Use the top box for the first item");
  frmvalidator.addValidation("quote_price_1_text","req","At least one quote price is required. Use the top box for the first pricing");
  </script>

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