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


<?php
include ("../navigation/header.php");
include ("../navigation/sales_sidebar.php");

	$d="";
	$s = $_GET['s'];
	$p = $_GET['p'];
	if ($_SESSION['p'] >= 4) {$d=1;}
	$error = $_SESSION['error'];
	$_SESSION['p']=$p;
	$_SESSION['s']=$s;
	
	
	if (isset($_GET['prev_button']) )
	   {
		 $_SESSION['p']= $_SESSION['p']-1;
	   }
		 
	if (isset($_GET['next_button']) )
	  {
		$_SESSION['p']=$_SESSION['p']+1;
	  }
	
		
	
if ($s==1) {
		
  $_SESSION['type'] = $_GET['type_text'];	
  $_SESSION['sort'] = $_GET['sort_group'];	
  
  
  if ($_SESSION['type']=="client") {
	
	$cust_id = $_GET['comp_name_select'];	
	$_SESSION['id'] = $cust_id;
	$table_name = $_SESSION['db_prefix']."_customer";
	$cust_query="SELECT account_type, comp_name, contact_1, cell_1, name_2, title FROM $table_name WHERE cust_id = '".$cust_id."' ";
	$cust_result = mySQL_query($cust_query) or die ("Error in query:   $query . * ". mySQL_error());
	$c0 = mysql_result($cust_result, 0, "account_type");
    
	if ($c0=="corporate") { 
			$_SESSION['company_name'] = mysql_result($cust_result, 0, "comp_name"); } 
	else { 
			$_SESSION['company_name'] = mysql_result($cust_result, 0, "title")." ".mysql_result($cust_result, 0, "name_2")." ".mysql_result($cust_result, 0, "comp_name"); 
		}
		
	$_SESSION['comp_contact'] = mysql_result($cust_result, 0, "contact_1");
	$_SESSION['contact_phone'] = mysql_result($cust_result, 0, "cell_1");
	$num = mysql_num_rows($cust_result);
	
	if ($num==0)
	{ 
	$_SESSION['error']=1;
	$_SESSION['p']=1;
	$_SESSION['type'] = "";	
	$_SESSION['sort'] = "";	
	?>
    <script language="javascript" type="text/javascript">
        <!--
		needToConfirm = false;
	    window.location="newQuoteWizbase.php?s=0&p=1";
        -->
     </script>
	
	<?php
	}
	
		$_SESSION['comp_contact'] = mysql_result($cust_result, 0, "contact_1");
		$_SESSION['contact_phone'] = mysql_result($cust_result, 0, "cell_1");
	
		
		
}

if ($_SESSION['type']=="contact") {
	
	$comp_name = $_GET['comp_name_text'];
	$name_2 = $_GET['name_2_text'];
	$title = $_GET['title_select'];
	$table_name = $_SESSION['db_prefix']."_customer";
	$cust_query="SELECT cust_id FROM $table_name WHERE comp_name = '".$comp_name."' AND name_2 = '".$name_2."' ";
	
    $cust_result = mySQL_query($cust_query) or die ("Error in query:   $query . * ". mySQL_error());
	$num = mysql_num_rows($cust_result);
	
	$_SESSION['company_name'] = $name_2.' '.$comp_name ;
		
	if (($num!=0))
	{  
	$_SESSION['error']=2;
	$_SESSION['p']=1;
	$_SESSION['type'] = "";	
	$_SESSION['sort'] = "";	
	$_SESSION['company_name'] = $name_2.' '.$comp_name ;
	
	}
	
	else {
	$status = "new";
	$account_type = $_GET['sort_group'];
	$comp_name = trim($_GET['comp_name_text']);
	$name_2 = trim($_GET['name_2_text']);
	$title = $_GET['title_select'];
	
	$bag_box = trim($_GET['bag_box_select']);
	$box_number = trim($_GET['box_number_text']);
	$post_place = trim($_GET['post_place_select']);
	$phone = trim($_GET['phone_text']);
	$fax = trim($_GET['fax_text']);
	$email = trim($_GET['email_text']);
	$_SESSION['name'] = $comp_name;
	
	$table_name = $_SESSION['db_prefix']."_customer";
	
	
    $contact_query = "INSERT INTO $table_name (`account_type`,`status`, `comp_name`, `name_2`,`title`, `bag_box`, `box_no`, `postal_place`, `phone`, `fax`, `email_1`) VALUES ('".$account_type."', '".$status."',  '".$comp_name."', '".$name_2."', '".$title."', '".$bag_box."', '".$box_number."', '".$post_place."', '".$phone."', '".$fax."', '".$email."') ";
   	execsql($contact_query);
	
	$table_name = $_SESSION['db_prefix']."_customer";
    $id_query = "SELECT  cust_id  FROM $table_name WHERE comp_name  = '".$comp_name."'  ";
	
	$id_result = mySQL_query($id_query);
    $_SESSION['id'] = mysql_result($id_result, 0, "cust_id");
	
	$_SESSION['company_name'] = $name_2.' '.$comp_name ;
	
}
	}
	
	}
		
	if($s==2) {
		$_SESSION['quote_date']  = $_GET['quote_date'];
		
		
		$_SESSION['comp_contact']  = $_GET['comp_contact_text'];
		$_SESSION['contact_phone']  = $_GET['contact_phone_text'];
		$_SESSION['project_no']  = $_GET['project_no_text'];
		$_SESSION['project_place']  = $_GET['project_place_select'];
		$_SESSION['description']  = $_GET['description_text'];
		$_SESSION['seller']  = $_GET['seller_select'];

	  
 	};
	
	if($s==3) {
		
		$table_name = $_SESSION['db_prefix']."_cash_quotation_lines_temp";
		$delete_query = "DELETE FROM $table_name WHERE  user_name = '".$_SESSION['username']."'   "; 
		execsql($delete_query);
		
$line_num = $_GET['line_num'];
if ($line_num>0) {
$i=0;
while ($i<$line_num) {
if (isset($_GET['line_checkbox'.$i])) {
$_SESSION['category'.$i] =	$_GET['category'.$i];
$_SESSION['index'.$i] =	$_GET['index'.$i];
$store_item_id = $_GET['store_item_id'.$i];
	

				$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, subCategory, price, price_2 FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
				$name_result = mySQL_query($name_query);
				$_SESSION['store_item_name'] = mysql_result($name_result, 0, "item_name");
				$price = mysql_result($name_result, 0, "price");
				$price_2 = mysql_result($name_result, 0, "price_2");
				$sub_category = mysql_result($name_result, 0, "subCategory");
				$_SESSION['store_item_id'] = $store_item_id;
				
$quantity = $_GET['quantity_text'.$i];

$table_name = $_SESSION['db_prefix']."_cash_quotation_lines_temp";
$receive_query = "INSERT INTO $table_name ( store_item_id, sub_category, quantity,  price, price_2, user_name) VALUES ('".$store_item_id."', '".$sub_category."', '".$quantity."', '".$price."', '".$price_2."', '".$_SESSION['username']."' ) ";
execsql($receive_query);

};
$i++;
}
}

	$table_name = $_SESSION['db_prefix']."_presets";
	$followup_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'follow_up' ";
	$followup_result = mySQL_query($followup_query);
	$days = mysql_result($followup_result, 0, "preset_value");
	
	
	$_SESSION['check_date'] = date("Y-m-d", strtotime(date("Y-m-d", strtotime($today)) . " +".$days." day"));
	
	if (date("l", strtotime($_SESSION['check_date'])) == "Sunday") {$_SESSION['check_date'] = date("Y-m-d", strtotime(date("Y-m-d", strtotime($_SESSION['check_date'])) . " +1 day")); }
	if (date("l", strtotime($_SESSION['check_date'])) == "Saturday") {$_SESSION['check_date'] = date("Y-m-d", strtotime(date("Y-m-d", strtotime($_SESSION['check_date'])) . " +2 day")); }
	

$_SESSION['transport'] = $_GET['transport_text'];	
	
	};
	
	if($s==4) {
	 
		 
	}
				
	?>

<!--style sheets-->
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<link href="../css/wait.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../window/dhtmlwindow.css" type="text/css" />
<link rel="stylesheet" href="../window/modal.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script type="text/javascript" src="../jscript/jquery.1.4.2.js"></script>
<script type="text/javascript" src="../window/dhtmlwindow.js"></script>
<script type="text/javascript" src="../window/modal.js"></script>
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>  
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script>

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

</head>


<body>


<div class="main_frame" style="height:auto; min-height:550px;">

<div class="page_head_frame">
  
<table width="678" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="547"><label class="label_page_head">Cash Sale Quotation
              <?php  echo $_SESSION['company_name'] ?>
          </label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
          <td width="131" align="center">&nbsp;</td>
        </tr>
    </table>
 </div>     
      <div class='wizard_paging_frame'>
       <table align="left">
      <tr>
      <td>
      <?php if ($_SESSION['p']==1) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;1</div>
      <div class="active_step_label"><br /><br /><br />
        Customer details</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;1</div>
      <div class="de_active_step_label"><br /><br /><br />
      Customer details</div></div>
      <?php } ?>
      
      </td>
      <td>
      <?php if ($_SESSION['p']==2) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;2</div>
      <div class="active_step_label"><br /><br /><br />
      Details</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;2</div>
      <div class="de_active_step_label"><br /><br /><br />
      Details</div></div>
      <?php } ?>
     </td>
     <td>
      <?php if ($_SESSION['p']==3) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;3</div>
      <div class="active_step_label"><br /><br /><br />
      Quote details</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;3</div>
      <div class="de_active_step_label"><br /><br /><br />
      Quote details</div></div>
      <?php } ?>
     </td>
     <td>
      <?php if ($_SESSION['p']==4) { ?>
      <div class="active_step_frame"><div class="active_step_head_label">&nbsp;4</div>
      <div class="active_step_label"><br /><br /><br />
      Finish</div></div>
      <?php } else { ?>
      <div class="de_active_step_frame"><div class="de_active_step_head_label">&nbsp;4</div>
      <div class="de_active_step_label"><br /><br /><br />
      Finish</div></div>
      <?php } ?>
     </td>
        </tr>
      </table>
      </div>
      </td>
      </tr>
      <tr>
      <td><?php 
	if ($_SESSION['p']==1) { include("newQuoteWiz1.php"); }
	if ($_SESSION['p']==2) { include("newQuoteWiz2.php"); }
	if ($_SESSION['p']==3) { include("newQuoteWiz3.php"); }
	if ($_SESSION['p']==4) { include("newQuoteWiz5.php"); }
	
    ?></td>
    </tr>
    </table>
    </div>

</div>

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