<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$tyrenum_veh='';

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

//$tablename='cf_client';

		if(isset($_POST['labtestsubmit'])){
		
			$purchase_status='0';
			if(isset($_POST['purchase_date'])){
			$purchase_date= date(('Y-m-d'),strtotime($_POST['purchase_date']));
			}
			
			if(isset($_POST['party_name'])){
			$party_name=addslashes($_POST['party_name']);
			}
			
			if(isset($_POST['purchase_quantity'])){
			$purchase_quantity=addslashes($_POST['purchase_quantity']);
			}
			
			if(isset($_POST['purchase_rate'])){
			$purchase_rate=addslashes($_POST['purchase_rate']);
			}
			
			if(isset($_POST['total_amt'])){
			$total_amt=addslashes($_POST['total_amt']);
			}
			
			if(isset($_POST['purchase_status'])){
			$purchase_status=addslashes($_POST['purchase_status']);
			}
			
			$addate = date('Y-m-d');
		   
		    $sql3 = mysql_query("insert into cf_purchase_booking (purchase_bookdate,purchase_partyid,purchase_quantity,purchase_rate,purchase_total,purchase_status,purchase_addate) values ('$purchase_date','$party_name','$purchase_quantity','$purchase_rate','$total_amt','$purchase_status','$addate')");
			
			//echo "insert into cf_purchase_booking (purchase_bookdate,purchase_partyid,purchase_quantity,purchase_total,purchase_status,purchase_addate) values ('$purchase_date','$party_name','$purchase_rate','$total_amt','$addate')";
			
			
			header("location:purchase_booking_list.php");					
						
			
			
}
			
			
			
		$pur_date='';
		$purvendorid='';
		$pur_qty='';
		$pur_amt='';
		$pur_total='';
		$purchasestatus='';
		
		if(isset($_REQUEST['lab_id'])){
			$id=$_REQUEST['lab_id'];
			//$tablename='cf_lab';
			$sqlObj->tablename="cf_purchase_booking";
			$condition=" where purchase_bookid='$id'";
			$sqlObj->condition=$condition;
			$sqlObj->fieldvalue="*";
			$fieldvalue=$sqlObj->fieldvalue;
			$sql=$sqlObj->SelectTable();

			$pur_date=date(('d-m-Y'),strtotime($sql['purchase_bookdate']));
			$purvendorid=$sql['purchase_partyid'];	
			$pur_qty=$sql['purchase_quantity'];	
			$pur_amt=$sql['purchase_rate'];	
			$pur_total=$sql['purchase_total'];
			$purchasestatus=$sql['purchase_status'];	
			
							
			
		}
		
		
		if(isset($_POST['labtestedit']))
		{
			
			if(isset($_POST['purchase_date'])){
			$purchase_date= date(('Y-m-d'),strtotime($_POST['purchase_date']));
			}
			
			if(isset($_POST['party_name'])){
			$party_name=addslashes($_POST['party_name']);
			}
			
			if(isset($_POST['purchase_quantity'])){
			$purchase_quantity=addslashes($_POST['purchase_quantity']);
			}
			
			if(isset($_POST['purchase_status'])){
			$purchase_status=addslashes($_POST['purchase_status']);
			}
			
			if(isset($_POST['purchase_rate'])){
			$purchase_rate=addslashes($_POST['purchase_rate']);
			}
			
			if(isset($_POST['total_amt'])){
			$total_amt=addslashes($_POST['total_amt']);
			}
			
			//$today = date('Y-m-d');
			
			  $sql3 = mysql_query("update cf_purchase_booking set purchase_bookdate='$purchase_date',purchase_partyid='$party_name',purchase_quantity='$purchase_quantity',purchase_rate='$purchase_rate',purchase_total='$total_amt',purchase_status='$purchase_status' where purchase_bookid=$id");
			//$purid = mysql_insert_id();
		header("location:purchase_booking_list.php");
		}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="scripts_date/jquery.js"></script>
<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>




<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
function validation(){
if(document.frmname.lab_date.value==''){
alert("Select a Date");
document.frmname.lab_date.focus();
return false;
}
if(document.frmname.lab_bill_no.value==''){
alert("Enter the Bill No");
document.frmname.lab_bill_no.focus();
return false;
}
/*if(document.frmname.lab_quantity.value==''){
alert("Enter the Quantity");
document.frmname.lab_quantity.focus();
return false;
}*/

if(document.frmname.bill_amt.value==''){
alert("Enter the Bill Amount");
document.frmname.bill_amt.focus();
return false;
}

if(document.frmname.company_name.value==''){
alert("Enter the Company Name");
document.frmname.company_name.focus();
return false;
}

if(document.frmname.veh_no.value==''){
alert("Enter the Vehicle No");
document.frmname.veh_no.focus();
return false;
}



if(document.frmname.lab_agent_id.value==''){
alert("Select the Lab Name");
document.frmname.lab_agent_id.focus();
return false;
}
/*var cnt=document.getElementById('divcnt').value;chasisnum1 enginenum1
for(i=1;i<=cnt;i++){alert(document.getElementById('vehiclenum'+i).value);
if(document.getElementById('vehiclenum'+i)){
if(document.getElementById('vehiclenum'+i).value==''){
alert("Enter the Vehicle Number");
document.getElementById('vehiclenum'+i).focus();
return false;
}
}
}*/
}

$(document).ready(function(){
$('#purchase_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});	

function calculaterate(){
	var quantity = document.getElementById('purchase_quantity').value;
	var rate = document.getElementById('purchase_rate').value;
	var total = quantity*rate;
	document.getElementById('total_amt').value = total;
}
</script>


<style>
.lableentrytext{
font-size: 12px;
color: #505050;
clear: both;
margin-bottom: 5px;
text-transform: capitalize;
}
</style>
</head>

<body>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
 <div class="tabbedArea">
  
  <div class="tabBody">
   <h1>Add Purchase Booking  </h1>
   <form name="frmname" method="post" action="">
   <div class="addEmp" style="margin-bottom:0px; border-bottom:0px solid;width:1000px;">
        <table width="70%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td valign="top">
           
        <div class="form1" >
            
         
       
       
	
	<div>     
	<p class="input1">Date</p>
	<input type="text" name="purchase_date" id="purchase_date" style="width:100px;" maxlength="100" class="input1" value="<?=$pur_date?>" />
	</div> 

	<div>     
	<p class="input1">Party Name</p>
	<select class="input1" name="party_name" id="party_name" >
     			<option value="">Select Vendor</option>
     			<?php 
					$sq_vendor="select * from cf_reseller";
					$arrven=mysql_query($sq_vendor);
					while($resven=mysql_fetch_array($arrven))
					{
					?>  
                    	
        				<option value="<?=$resven['reseller_id']?>" <? if($resven['reseller_id']==$purvendorid) {?>selected<? }?>   ><?=$resven['res_name']?></option>
               		<?php
					}
	 				?>
     		</select>
	
	</div>  


	<div>     
	<p class="input1">Quantity</p><input type="text" name="purchase_quantity" id="purchase_quantity" class="input1" onKeyUp="calculaterate();" value="<?=$pur_qty?>" >
	</div>



	</div>
	</td>
	<td valign="top"><div class="form1">
	<div>     
	<p class="input1">Rate</p>
	<input type="text" name="purchase_rate" id="purchase_rate" class="input1" value="<?=$pur_amt?>" onKeyUp="calculaterate();" >
	</div>    

	<div>     
	<p class="input1">Total Amount</p>
	<input type="text" name="total_amt" id="total_amt" class="input1" value="<?=$pur_total?>" >
	</div> 
	
	<div>
		<p  class="input1" style="padding-top:20px;">Status<span style="color:#FF3300">*</span>
			<input type="checkbox" name="purchase_status"  class="input1 " <?php if($purchasestatus==1){?> checked <?php }?> value="1" >  
		</p>
    </div>


	

	 
		 
           <div>
            &nbsp;
            </div>
            </div></td>
          </tr>
           <tr>
            <td colspan="2"><div class="searchField1">
        
           
                <?php 
                 	if(empty($_REQUEST['lab_id']))
					{ ?>
					  <input type="submit" name="labtestsubmit" value="submit" class="submit-btn" onClick="return validation_1()"  >
                <?php } else { ?>
                	  <input type="submit" name="labtestedit" value="update" class="submit-btn" onClick="return validation_1()"  >
                <?php } ?>               
        </div>
        </td>
          </tr>
        </table>
 

<div class="mand"><p>Fields marked <span style="color:#FF3300">*</span> are Mandatory</p></div>
</div>
   </form>
   </div>
 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
</html>


		






