<?php
include('connection.php');
$Entry_date=date('Y-m-d');
$date=(explode('-',$Entry_date));
$year=substr($date[0],2,2);
$month=$date[1];


$Emp;
$username;
$Rights;
$Emp_id=$username;
//echo $Emp_id;
$e=(explode(' ',$Emp));
$user=substr($e[0],0,3);


$sql="SELECT MAX(`Sr_no`)srno FROM `quotation_new`";
$result=mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die ("Query Fail:".mysqli_error($GLOBALS["___mysqli_ston"]));

while($rw=mysqli_fetch_assoc($result))
{
if($rw['srno']==NULL)
{
$srno=1;
}	
else
{
$sr=$rw['srno'];

$srno=$sr+1;
}
}
?>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="content-type" content="text/html; charset=WINDOWS-1252" >
<title>Update Ideal Quotation</title>
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
</script>

</head>

<body background="Image/background-color-block.png" style="background-attachment: fixed" onLoad="dis();">

<SCRIPT type="text/javascript" src="js/CommanValidationforNumber.js"></script>
<script>

function dis()
{ 

var Terms1=document.getElementById('Terms1').disabled=true;
var Terms2=document.getElementById('Terms2').disabled=true;
document.getElementById('search_table_div4').style.display="none";
var username=document.getElementById('Emp_id').value;
//alert(username);
}

function Replace_spl(val)
{
var l=val;
m=l.replace(/\'+/g,'\\\'');
n=m.replace(/\\+/g,'\\\\');
f=encodeURIComponent(n);
return(f);
}

 
 function poponload2(Sr_no)
{
try
{
var Sr_no=Sr_no;

var abc="?Sr_no="+Sr_no;

    testwindow = window.open("Ideal_quo_parts_update.php"+abc, "mywindow", "scrollbars=1,width=750,height=550");
     
    testwindow.moveTo(0, 0); 
 }

catch(err)
{
 txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.message+ " \n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
}

 }
 
 // **********************************************      UPDATE DATA       ***********************************************
 function Update_data()
{
try
{
	
	var currentTime = new Date()
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds =currentTime.getSeconds();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var time=day +'-'+month+'-'+year+'_'+hours+':'+minutes+':'+seconds;

var Company=document.getElementById('Company').value;
var Ideal=document.getElementById('Ideal').value;
var Ideal_name=document.getElementById('Ideal_name').value;

var g=Replace_spl(Ideal_name);
//g=g.replace(/\&+/g,'\\\&');

var Terms=document.getElementById('Terms').value;
var Terms1=document.getElementById('Terms1').value;
var Terms2=document.getElementById('Terms2').value;
var Title=document.getElementById('Title').value;	

var Transport=document.getElementById('Transport').value;
var Wastage=document.getElementById('Wastage').value;
var Profit=document.getElementById('Profit').value;
var Annexure=document.getElementById('Annexure').value;
var Increment=document.getElementById('Increment').value; //margin
var Inst=document.getElementById('Inst').value;
var Inst_charges=document.getElementById('Inst_charges').value; 


if (window.XMLHttpRequest)
 	 	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  http1=new XMLHttpRequest();
 		}
		else
		 {// code for IE6, IE5
		  http1=new ActiveXObject("Microsoft.XMLHTTP");
		 }
		http1.onreadystatechange=function()
		{
			if (http1.readyState==4 )
					 {
					 		 var display= document.getElementById('search_table_div');
		 				display.innerHTML = http1.responseText;
					
					}
		}			 
			var que =  "?Ideal="+Ideal+"&Ideal_name="+g+"&time="+time+"&Terms="+Terms+"&Terms1="+Terms1+"&Terms2="+Terms2+"&Title="+Title+"&Company="+Company+"&Transport="+Transport+"&Wastage="+Wastage+"&Profit="+Profit+"&Annexure="+Annexure+"&Increment="+Increment+"&Inst="+Inst+"&Inst_charges="+Inst_charges;
			alert(que);
					   http1.open("GET","Ideal_quotation_update_submit.php" + que, true);
					  //alert("nnmnmnmn");
					 http1.send(null);
					 
 }

catch(err)
{
 txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.message+ " \n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
}
}

 
 
 
var respo;
function load_data()
{
//alert('Hiiiiii');
var Company=document.getElementById('Company').value;
//alert(Company);
var f=document.getElementById('Ideal_name').value;
var g=Replace_spl(f);
Ideal_name=g.replace(/\&+/g,'\\\&');
var Ideal=document.getElementById('Ideal').value;

if( Ideal_name=='' )
{
document.getElementById("search_table_div").innerHTML="";
}
else
	{	
	
		if (window.XMLHttpRequest)
 	 	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  http1=new XMLHttpRequest();
 		}
		else
		 {// code for IE6, IE5
		  http1=new ActiveXObject("Microsoft.XMLHTTP");
		 }
		http1.onreadystatechange=function()
		{
			if (http1.readyState==4 )
					 {	
					//alert(http1.responseText);
					 				
       var display= document.getElementById('search_table_div');
		 				display.innerHTML = http1.responseText;
						load_Increment();
					
								 }
		}			 
			var que =  "?Company="+Company+"&Ideal_name="+Ideal_name+"&Ideal="+Ideal;
			//alert(que);
					  http1.open("GET","Ideal_quotation_update_div.php" + que, true);
					 http1.send(null);
		
	}

}

var Title;
function load_Increment()
{
//alert('load_Increment');
var Ideal=document.getElementById('Ideal').value;
var f=document.getElementById('Ideal_name').value;
var g=Replace_spl(f);
Ideal_name=g.replace(/\&+/g,'\\\&');

if(Ideal=='')
{
	//alert('ideal empty');
document.getElementById('Title').value='';
}
else
	{	
	
		if (window.XMLHttpRequest)
 	 	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  http1=new XMLHttpRequest();
 		}
		else
		 {// code for IE6, IE5
		  http1=new ActiveXObject("Microsoft.XMLHTTP");
		 }
		http1.onreadystatechange=function()
		{
			if (http1.readyState==4 )
					 {	
					 Title=http1.responseText;
					 //alert(Title);
					 	show_stock2();
										
		 }
		}			 
			var res = "?Ideal="+Ideal+"&Ideal_name="+Ideal_name;
		//alert(res);
					  http1.open("GET","list_Title.php" + res, true);
					 http1.send(null);
		
	}

}

function show_stock2()
{					
//alert('show_stock2');
		var data=Title.split("#");
		//alert(data);
		var count=data.length;
		//alert(count);
for(var i in data)
{
    //alert(data[i]);
}
document.getElementById('Terms').value=data[0];
document.getElementById('Terms1').value=data[1];
document.getElementById('Terms2').value=data[2];
document.getElementById('Title').value=data[3];	
document.getElementById('Transport').value=data[4];
document.getElementById('Wastage').value=data[5];
document.getElementById('Profit').value=data[6];
document.getElementById('Increment').value=data[7];
document.getElementById('Annexure').value=data[8];
document.getElementById('Inst').value=data[9];
document.getElementById('Inst_charges').value=data[10];


/*
if(data[9]!='undefined' && data[9]!='')
{

document.getElementById('search_table_div4').style.display="block";
document.getElementById('chk1').checked=true;
document.getElementById('Inst_charges').value=data[8];
document.getElementById('Inst').value=data[7];
}
else
{
document.getElementById('chk1').checked=false;
document.getElementById('search_table_div4').style.display="none";
}
*/

		
}


var Ideal_name; 
function list_name()
{
try
{
//alert('fg');
var Ideal=document.getElementById('Ideal').value;
if(Ideal=='')
{
document.getElementById('Ideal_name').value='';
}
else
{
if (window.XMLHttpRequest)
 	 	{// code for IE7+, Firefox, Chrome, Opera, Safari
		  http1=new XMLHttpRequest();
 		}
		else
		 {// code for IE6, IE5
		  http1=new ActiveXObject("Microsoft.XMLHTTP");
		 }
		http1.onreadystatechange=function()
		{	
			if (http1.readyState==4 )
					 {
					 Idea_name=http1.responseText;
					 //alert(Idea_name);
						show_namelists();				
					 }
		}			 
			var que =  "?Ideal="+Ideal;
			//alert(que);
					  http1.open("GET","list_ideal_quo_names_.php" + que, true);
					 http1.send(null);

}
 }

catch(err)
{
 txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.message+ " \n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
}
}

function show_namelists()
			{	
			
			var data=Idea_name.split("#");
			//alert(data);
				var count=data.length;
				var combo = document.getElementById('Ideal_name');

				var j=1;
				var village='';
				combo.options.length=1;
				for(var i=0;i<=count;i++)
				{
					if(data[i] != '')
					{
						village = data[i].split('!');
						combo.options[j]=new Option(village[1],village[0]);
						j++;
					}
				  }	
 			}

function div_hide()
{
document.getElementById('search_table_div4').style.display="none";
}


function Show_labour(id)
{

//alert(id);
var Ideal=document.getElementById('Ideal').value;
if(Ideal=='')
{
						alert('Please Select Ideal Quotation Name first !');
						return;
}
						
else
{
											
											if(id=='search_table_div4')
											{
														if(document.getElementById('c1').checked==false)
														{
																	div_hide();
														}
						
										else
										{
														//div_hide();
														document.getElementById(id).style.display="block";
										}
}


//else
//{
//div_hide();
 //document.getElementById(id).style.display="block";
// }
 
}
}

function Edit(no)
{
//alert('hi');
switch(no)
{
case "1":
{
var Terms1=document.getElementById('Terms1').disabled=false;
}
break;
case "2":
{
var Terms2=document.getElementById('Terms2').disabled=false;
}
break;
}
}


</script>

<table border="1" width="100%" height="110%">
	<tr>
		<td height="136" colspan="3" style="line-height: 100%; text-align: right" valign="bottom">

		<?php include('Logo.php'); ?>
		<p>
		<img border="0" src="Image/Home1.png" width="55" height="55" onclick="window.location.href='home.php'">
				</td>
	</tr>
	<tr>
		<td width="4%" height="23">&nbsp;</td>
		<td width="91%" valign="top" height="23" background="Menu/images/bg.jpg">
			<?php include('Menu/Menu.php'); ?>	</td>
		<td width="4%" height="23">&nbsp;</td>
	</tr>
	<tr>
		<td width="4%">&nbsp;</td>
		<td width="91%" valign="top" align="center">
			<table border="0" width="78%">
				<tr>
					<td width="242" height="24"><font face="Leelawadee">Company
					<font color="#FF0000">*</font></font><input type="hidden" name="Rights" id="Right"  size="14" value='<?php echo $Rights; ?>'></td>
					<td colspan="21" height="24"><font size="3" face="Leelawadee">
				<select size="1" name="Company" id='Company' onchange='load_Add();'>
				<option value=''>- - - - - - - - Select - - - - - - - -		<?php
			
			
		$i=0;			
		$Comp_query ="SELECT `Company_name`,`Company_code`FROM `company_osmosis` ";
		$Comp_result=mysqli_query($GLOBALS["___mysqli_ston"], $Comp_query) or die('Query Failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
		
		while($count = mysqli_fetch_assoc($Comp_result))
		{
		$Comp=$count['Company_name'];
		$Comp_name[$i]=$Comp;
		$code=$count['Company_code'];
		$Company_code[$i]=$code;
		$i++;
		}
		$res=count($Comp_name);
		for($a=0;$a<$res;$a++)
		{
echo<<<jigar

<option value="$Company_code[$a]">$Comp_name[$a]</option>
jigar;

		}
		?>
			</option>
				
			
		
		

				
				</select></font></td>
				</tr>
				<tr>
					<td width="242" height="24"><font face="Leelawadee">Ideal 
					Quotation</font>
					<?php echo "<input type='hidden'  name='Emp' id='Emp' size='9' value='$Emp'>";?><font face="Leelawadee">
					<font color="#FF0000">*</font></font></td>

					<td height="24" colspan="4"><font size="3" face="Leelawadee">
				<select size="1" name="Ideal" id='Ideal'  onchange='list_name();' style="text-align: left">
				<option value=''>- - - - - - - - Select - - - - - - - -</option>
				<?php
		$i=0;			
		$Category_query ="SELECT Distinct(`Ideal_quotation`)ID FROM `quotation_ideal` ";
		$Category_result=mysqli_query($GLOBALS["___mysqli_ston"], $Category_query) or die('Query Failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
		
		while($count = mysqli_fetch_assoc($Category_result))
		{
		$Ideal_quotation=$count['ID'];
		
		$Ideal[$i]=$Ideal_quotation;
			
		$i++;
		}
		 
		$res=count($Ideal);
		for($a=0;$a<$res;$a++)
		{
echo<<<jigar

<option value="$Ideal[$a]">$Ideal[$a]</option>
jigar;

		}
		?>	

				</select></font></td>

					<td height="24" colspan="3"><font size="3" face="Leelawadee">
				<select size="1" name="Ideal_name" id='Ideal_name' onfocus='list_name();' onchange='load_data();' style="text-align: left">
				<option value=''>- - - - - - - - Select - - - - - - - -</option>
				
				</select></font></td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>

					<td colspan="2" height="24">&nbsp;</td>

					<td height="24">&nbsp;</td>
				</tr>

				
				
				<tr>
					<td width="27%" valign="top"><font face="Leelawadee">Quotation Title
					</font></td>
					<td colspan="21"><form name="myform">
					<textarea rows="3"  name="Title" id='Title'   cols="39" onKeyDown="limitText(this.form.Title,this.form.countdown,160);"
onKeyUp="limitText(this.form.Title,this.form.countdown,160);"  onblur = "javascript:this.value=removeSpaces(this.value);"></textarea>
<font size="1"><p>(Max Rows : 4 , Max characters: 160)<br>
You have <input  type="text" name="countdown" size="3" value="160"> characters left.</font></form></td>
				</tr>
				
								
			<!--<tr>
					<td width="27%" valign="top"><font face="Leelawadee">Installation & Labour Charges</font></td>
					<td colspan="21">
							
					<input type="checkbox" name="C1" id='chk1' value="ON" onclick="Show_labour('search_table_div4');"></td>
				</tr> 
				
				<tr>
					<td width="27%" valign="top">&nbsp;</td>
					<td colspan="21">
					
					<div id="search_table_div4" align="left">
							
					
		<form name="myform2">
		<font face="Leelawadee" color="#FF0000">Title</font> 
		<input type="text" name="Inst" id='Inst' size="81" maxlength='38'  onblur='javascript:this.value=this.value.toUpperCase();' >
			<p>		
			<textarea rows="3"  name="Inst_charges"   id='Inst_charges' cols="39" onKeyDown="limitText(this.form.Inst_charges,this.form.countdown,160);"
onKeyUp="limitText(this.form.Inst_charges,this.form.countdown,160);"  onblur = "javascript:this.value=removeSpaces(this.value);"></textarea>
<font size="1"><p>(Max Rows : 4 , Max characters: 160)<br>
You have <input  type="text" name="countdown" size="3" value="160"> characters left.</font></form>					
			</p>
						</div> 

					</td>
				</tr>-->
				
				<tr>
					<td width="27%" height="16" colspan="2">
					<font face="Leelawadee">Installation &amp; Labour Charges</font></td>
					<td valign="top" colspan="10">
					
					<input type="checkbox" name="C1" id='c1' value="ON" onclick="Show_labour('search_table_div4');"></td>
				</tr>
				
				
				<tr>
					<td width="20%" height="16" ></td>
					<td valign="top" colspan="10">
					
					
						<div id="search_table_div4" align="left">
							
		<font face="Leelawadee" color="#00000">Title</font>
		<form name="myform2">
		<input type="text" name="Inst" id='Inst' size="35" maxlength='38' value="Installation & Labour Charges" onblur='javascript:this.value=this.value.toUpperCase();' >
			<p>		
			<textarea rows="3"  name="Inst_charges" id='Inst_charges' cols="50" onKeyDown="limitText(this.form.Inst_charges,this.form.countdown,160);"
onKeyUp="limitText(this.form.Inst_charges,this.form.countdown,160);"  onblur = "javascript:this.value=removeSpaces(this.value);">
</textarea>
<font size="1"><p>(Max Rows : 4 , Max characters: 160)<br>
You have <input readonly type="text" name="countdown" size="3" value="160"> characters left.</font></form>					
			</p>
						</div>
			</td>
				</tr><tr>	<td height="31">&nbsp;</td></tr>
				
				
				<tr>
									
					<td height="24">
					<p align="center"><font face="Leelawadee">Transport
					 </font></td>
					 
					<td height="24">
					<font face="Leelawadee">
					 <input name="Transport" id="Transport" size="9" value='0'    onkeypress="return numbersonly(this,event);" style="border:1px solid #FFFFFF; float: left">&nbsp;
					<font color="#FF0000"><u>Rs</u>.</font></font></td>
					
					<td height="24">
					<p align="center"><font face="Leelawadee">Margin
					 </font></td>
					<td height="24">
					<font face="Leelawadee">
					 <input name="Increment" id="Increment" size="9" value='0'    onkeypress="return numbersonly(this,event);" style="border:1px solid #FFFFFF; float: left">&nbsp;
					<font color="#FF0000"><u>%</u>.</font></font></td>
					
					
					<td height="24">
					<font face="Leelawadee">Wastage</font></td>
					<td height="24">
					&nbsp;</td>
					
					<td height="24">
					<p align="left">
					 <font size="3" face="Leelawadee">
					 <input name="Wastage" id="Wastage" size="9" value='0'   onkeypress="return numbersonly(this,event);"> </font>
						<font color="#FF0000" face="Leelawadee">%</font></td>
						
					<td height="24">
					<font face="Leelawadee">Profit OH</font></td>
					
					<td height="24" colspan="15">
					 <font size="3" face="Leelawadee">
					 <input name="Profit" id="Profit" size="9" value='0'   onkeypress="return numbersonly(this,event);"> </font>
						<font color="#FF0000" face="Leelawadee">%</font></td>
				</tr>
				
				<tr>
					<td width="242" height="29"><font face="Leelawadee">Special 
					Terms &amp; Conditions 1</font><td width="659" height="29" colspan="21">
					<input type="text" name="Terms" id='Terms' size="81"  ></td>
					
				</tr>
				<tr>
					<td width="242" height="31"><font face="Leelawadee">Special 
					Terms &amp; Conditions 2</font><td width="594" height="31" colspan="19">
					<input type="text" name="Terms1" id='Terms1' size="81"   value="Vat/Service tax will be extra as applicable" ></td>
					
					<td width="82" height="31" align="left" colspan="2">
					<font size="3" face="Leelawadee">
					<input type="submit" value="Edit" name="Print1" id='Back1' style="font-family: Leelawadee; font-size: 12pt" onclick="Edit('1');"></td>
					
				</tr>
				<tr>
					<td width="242" height="31"><font face="Leelawadee">Special 
					Terms &amp; Conditions 3</font><td width="594" height="31" colspan="19">
					<input type="text" name="Terms2" id='Terms2' size="81"  value="We will check and use existing cable if it is ok or we will replace it as per our quotation" ></td>
					
					<td width="82" height="31" align="left" colspan="2">
					<font size="3" face="Leelawadee">
					<input type="submit" value="Edit" name="Print0" id='Back0' style="font-family: Leelawadee; font-size: 12pt" onclick="Edit('2');"></td>
					
				</tr>
				<tr>
					<td width="242" height="21" valign="top">
					<font face="Leelawadee">Annexure</font><td width="659" height="21" colspan="21">
					<textarea rows="4" name="Annexure" id='Annexure'  cols="61"></textarea></td>
					
				</tr>
				<tr>
					<td width="242" height="21">&nbsp;
					<td width="659" height="21" colspan="21">&nbsp;
</td>
					
				</tr>
				<tr>
					<td width="242" height="31">&nbsp;	
							
</td>
					<td height="31" valign="top" colspan="21"><font size="3" face="Leelawadee">
					<input type="submit" value="Update" name="Update" id='Update' onclick='Update_data();' style="font-family: Leelawadee; font-size: 12pt">&nbsp;&nbsp;
					&nbsp; &nbsp;
					&nbsp;
					<!--<input type="button" value="Print Quo" onclick="JavaScript:printPartOfPage('search_table_div');" name="Print_Quo" id="Print_Quo" style="font-family: Leelawadee; font-size: 10pt" disabled></font></td>-->
				</tr>
				<tr>
					<td width="242">&nbsp;</td>
					<td colspan="21">&nbsp;</td>
				</tr>
				</table>
				<div id="search_table_div" align="center">
				

				</div>  

		</td>
		<td width="4%">&nbsp;</td>
	</tr>
	</table>

</body>

</html>