<?
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';
		$tinratecommCheck  = 0;
		if(isset($_POST['purchasesubmit'])){
			
			if(isset($_POST['vendor_id'])){
			$vendorid=addslashes($_POST['vendor_id']);
			}
			
			if(isset($_POST['product_id'])){
			$productid=addslashes($_POST['product_id']);
			}	
					
			if(isset($_POST['ffa_requested'])){
			$ffarequested=addslashes($_POST['ffa_requested']);
			}	
			
			if(isset($_POST['purchasetype'])){
			$purchasetype=addslashes($_POST['purchasetype']);
			}	
			
			if(isset($_POST['commodity_val'])){
			$commodityval=addslashes($_POST['commodity_val']);
			}	
			
			if(isset($_POST['tin_rate'])){
			$tinrate=addslashes($_POST['tin_rate']);
			}	
			
			if(isset($_POST['commodity_rate_total'])){
			$commodityratetotal=addslashes($_POST['commodity_rate_total']);
			}	
			
			if(isset($_POST['tanker_freight_chg'])){
			$tankerfreightchg=addslashes($_POST['tanker_freight_chg']);
			}	
			
			if(isset($_POST['tonnage_rate'])){
			$tonnagerate=addslashes($_POST['tonnage_rate']);
			}	
			
			if(isset($_POST['tanker_total'])){
			$tankertotal=addslashes($_POST['tanker_total']);
			}	
			
			if(isset($_POST['passing_chg'])){
			$passingchg=addslashes($_POST['passing_chg']);
			}		
			
			if(isset($_POST['tin_rate_comm_check'])){
			$tinratecommCheck = addslashes($_POST['tin_rate_comm_check']);
			}

			if(isset($_POST['tin_rate_comm'])){
			$tinratecomm=addslashes($_POST['tin_rate_comm']);
			}
			
			if(isset($_POST['ffa_got'])){
			$ffagot=addslashes($_POST['ffa_got']);
			}
			
			if(isset($_POST['ffa_given'])){
			$ffagiven=addslashes($_POST['ffa_given']);
			}
			
			if(isset($_POST['rtgs_chg'])){
			$rtgschg=addslashes($_POST['rtgs_chg']);
			}
			
			if(isset($_POST['weight_bridge'])){
			$weightbridge=addslashes($_POST['weight_bridge']);
			}
			
			if(isset($_POST['lab_testing'])){
			$labtesting=addslashes($_POST['lab_testing']);
			}
			
			if(isset($_POST['other_expense'])){
			$otherexpense=addslashes($_POST['other_expense']);
			}
			
			if(isset($_POST['tax_perkg'])){
			$taxper=addslashes($_POST['tax_perkg']);
			}	
			
			if(isset($_POST['tax_total'])){
			$taxtotal=addslashes($_POST['tax_total']);
			}	
			
			if(isset($_POST['grand_total'])){
			$grandtotal=addslashes($_POST['grand_total']);
			}
			
			if(isset($_POST['purchase_date'])){			
			$purchase_date = date(('Y-m-d'),strtotime($_POST['purchase_date']));
			}
			
			if(isset($_POST['pass_agent_id'])){
			$passagent_id=addslashes($_POST['pass_agent_id']);
			}
			
			if(isset($_POST['vehicletype'])){
			$vehicletype=addslashes($_POST['vehicletype']);
			}
			
			if(isset($_POST['vehicle_id'])){
			$vehicle_id=addslashes($_POST['vehicle_id']);
			}
			
			if(isset($_POST['drivername'])){
			$drivername=addslashes($_POST['drivername']);
			}
			
			
			
			
			
			
			$today = date('Y-m-d');
			
			$sql2 = mysql_query("insert into cf_oilpurchase (pur_vendor_id,pur_prd_id,pur_ffa_req,pur_type,pur_com_kg,pur_tin_rate,pur_com_total,pur_tank_tonne,pur_tonne_rate,pur_tank_total,pur_pass_chg,pur_tin_comm,pur_ffa_got,pur_ffa_rate,pur_rtgs_chg,pur_weight_brdg,pur_lab_test,pur_other_exp,pur_tax_per,pur_tax_rate,pur_total,pur_payable,pur_addate,pass_agent,veh_type,tin_rate_comm_check,vehicleid,driver_names) values ('$vendorid','$productid','$ffarequested','$purchasetype','$commodityval','$tinrate','$commodityratetotal','$tankerfreightchg','$tonnagerate','$tankertotal','$passingchg','$tinratecomm','$ffagot','$ffagiven','$rtgschg','$weightbridge','$labtesting','$otherexpense','$taxper','$taxtotal','$grandtotal','$grandtotal','$purchase_date','$passagent_id','$vehicletype','$tinratecommCheck','$vehicle_id','$drivername')");
			$purid = mysql_insert_id();
			
		   $sql3 = mysql_query("insert into cf_purchase (purchaseid,purchase_vendorid,purchase_prdid,purchase_total,purchase_type,purchase_addate) values ('$purid','$vendorid','$productid','$grandtotal','oil','$purchase_date')");	
		   
		  
		   $reselleres = mysql_query("select * from cf_ledger where ledgertype = 'vendorledger' and empid = '$vendorid'");
		   $resellrw = mysql_fetch_array($reselleres);
		   $ledgerids = $resellrw['ledgerid'];
		   
		   $respassres = mysql_query("select * from cf_ledger where ledgertype = 'passingagentledger' and empid = '$passagent_id'");
		   $respassrw = mysql_fetch_array($respassres);
		   $pass_agent_id = $respassrw['ledgerid'];
		   
		   $reslabres = mysql_query("select * from cf_ledger where ledgertype = 'labledger' and empid = '$passagent_id'");
		   $reslabrw = mysql_fetch_array($reslabres);
		   $lab_agent_id = $reslabrw['ledgerid'];
		   
		   $acc_ref=mysql_query("select max(account_reference) as account_reference  from cf_purchase_account");
			 $acc_refrow=mysql_fetch_array($acc_ref);
			 if(mysql_num_rows($acc_ref) >0)
			 {
			 	$acc_reference=$acc_refrow['account_reference'];
			 }
			 else
			 {
			 	$acc_reference=0;
			 }
		   
		   $acc_reference=$acc_reference+1;
		   $sql31 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purch_id) values ('$purid','$grandtotal','2','1000','$purchase_date','$today','$acc_reference','$productid','$purid')");
		   
		   
		   $sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference,prdt_type,purch_id) values ('$purid','$grandtotal','1','$ledgerids','$purchase_date','$today','$acc_reference','$productid','$purid')");	
		   
		   /*$acc_reference=$acc_reference+1;
		   $sql33 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference) values ('$purid','$passingchg','2','1041','$purchase_date','$today','$acc_reference')");	
		   
		   $sql34 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference) values ('$purid','$passingchg','1','$pass_agent_id','$purchase_date','$today','$acc_reference')");	*/
		   
		   
		   
		  
		   
		   
		   mysql_query("update cf_acountspayable set `pendingamount`=`pendingamount`+$grandtotal where vendorid= '$vendorid'"); /// nithya
		   
		   $sq_stock=mysql_query("select * from cf_stock");
		   
		  
		   
		   if(mysql_num_rows($sq_stock) > 0)
		   {
		   		$rw = mysql_fetch_array($sq_stock);
				
				 if($productid == 1)
		   		 {
		   			$stockpalmoil = $rw['stock_palmoil'] + $commodityval;
		   			$sql4 = mysql_query("update cf_stock set stock_palmoil = '$stockpalmoil',add_date='$purchase_date'");	
		   		 }
				 else if($productid == 2)
				 {
				 	$stockcoconutoil = $rw['stock_coconutoil'] + $commodityval;
		   			$sql4 = mysql_query("update cf_stock set stock_coconutoil = '$stockcoconutoil',add_date='$purchase_date'");	
				 }
				
				
		   }
		   
		   /* if(isset($_POST['lab_date'])){
			$labdate= date(('Y-m-d'),strtotime($_POST['lab_date']));
			}
			
			if(isset($_POST['lab_bill_no'])){
			$lab_billno=addslashes($_POST['lab_bill_no']);
			}
			
			if(isset($_POST['lab_quantity'])){
			$labquantity=addslashes($_POST['lab_quantity']);
			}
			
			if(isset($_POST['lab_testing'])){
			$labamount=addslashes($_POST['lab_testing']);
			}
			
			if(isset($_POST['veh_no'])){
			$vehno=addslashes($_POST['veh_no']);
			}
			
			if(isset($_POST['company_name'])){
			$companyname=addslashes($_POST['company_name']);
			}
			
			if(isset($_POST['lab_agent_id'])){
			$labname=addslashes($_POST['lab_agent_id']);
			}
		   
		    $sql3 = mysql_query("insert into cf_lab (pur_id,lab_date,lab_billnum,lab_qty,lab_bill_amt,lab_vehicle_no,lab_company,lab_name) values ('$purid','$labdate','$lab_billno','$labquantity','$labamount','$vehno','$companyname','$labname')");	
			
		   $acc_reference=$acc_reference+1;
		   $sql35 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference) values ('$purid','$labtesting','2','1040','$purchase_date','$today','$acc_reference')");	
		   
		   $sql36 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference) values ('$purid','$labtesting','1','$lab_agent_id','$purchase_date','$today','$acc_reference')");	*/
		   
		   
		   /*else
		   {	
		   		$sql5 = mysql_query("insert into cf_stock (stock_oil,add_date) values ('$commodityval','$purchase_date')");	
		   }*/
    	 	
			header("location:purchase_list.php");				
		}
			
			//exit;	
			

			$purtype = '';
			$purvendorid =  '';
			$purprdid = '';
			$purffareq = '';
			$purcomkg = '';
			$purtinrate = '';
			$purcomtotal = '';
			$purtanktonne = '';
			$purtonnerate = '';
			$purtanktotal = '';
			$purpasschg = '';
			$purtincomm = '';
			$purffa_got = '';
			$purffarate = '';
			$purrtgschg = '';
			$purweightbrdg = '';
			$purlabtest = '';
			$purotherexp = '';
			$purtaxper = '';
			$purtaxrate = '';
			$purtotal = '';
			$puraddate ='';
			$vehicleid ='';
			$driver_names ='';	
			
			$lab_date_1='';	
			$lab_billnum_1='';	
			$lab_qty_1='';	
			$lab_bill_amt_1='';	
			$lab_vehicle_no_1='';						
			$lab_company_1='';
			$lab_name_1='';	
			$veh_type='';					
			$passagent='';
			$pur_type='';
			
			if(isset($_REQUEST['pur_mainid'])){
			
				$id=$_REQUEST['pur_mainid'];
				$tablename='cf_client';
				$sqlObj->tablename="cf_oilpurchase";
				$condition=" where pur_id='$id'";
				$sqlObj->condition=$condition;
				$sqlObj->fieldvalue="*";
				$fieldvalue=$sqlObj->fieldvalue;
				$sql=$sqlObj->SelectTable();
				$purtype = $sql['pur_type'];
				$purvendorid = $sql['pur_vendor_id'];
				$purprdid = $sql['pur_prd_id'];
				$purffareq = $sql['pur_ffa_req'];
				$purcomkg = $sql['pur_com_kg'];
				$purtinrate = $sql['pur_tin_rate'];
				$purcomtotal = $sql['pur_com_total'];
				$purtanktonne = $sql['pur_tank_tonne'];
				$purtonnerate = $sql['pur_tonne_rate'];
				$purtanktotal = $sql['pur_tank_total'];
				$purpasschg = $sql['pur_pass_chg'];
				$purtincomm = $sql['pur_tin_comm'];
				$purffa_got = $sql['pur_ffa_got'];
				$purffarate = $sql['pur_ffa_rate'];
				$purrtgschg = $sql['pur_rtgs_chg'];
				$purweightbrdg = $sql['pur_weight_brdg'];
				$purlabtest = $sql['pur_lab_test'];
				$purotherexp = $sql['pur_other_exp'];
				$purtaxper = $sql['pur_tax_per'];
				$purtaxrate = $sql['pur_tax_rate'];
				$purtotal = $sql['pur_total'];
				//$puraddate = $sql['pur_addate'];
				$puraddate=date(('d-m-Y'),strtotime($sql['pur_addate']));
				$passagent = $sql['pass_agent'];
				$veh_type = $sql['veh_type'];
				$vehicleid = $sql['vehicleid'];
				$driver_names = $sql['driver_names'];	
				
				$rqry=mysql_query("SELECT *  FROM cf_lab where pur_id='".$id."'");
									
						if($rqry && mysql_num_rows($rqry)>0)
						{
							$sobj=mysql_fetch_object($rqry);
							{
								
								$lab_date_1=date(('d-m-Y'),strtotime($sobj->lab_date));		
								$lab_billnum_1=$sobj->lab_billnum;	
								$lab_qty_1=$sobj->lab_qty;	
								$lab_bill_amt_1=$sobj->lab_bill_amt;	
								$lab_vehicle_no_1=$sobj->lab_vehicle_no;						
								$lab_company_1=$sobj->lab_company;
								$lab_name_1=$sobj->lab_name;						
								
							}
						}
				
				
				
				
				if(isset($_POST['vendor_id'])){
				$vendorid=addslashes($_POST['vendor_id']);
				}
				
				if(isset($_POST['product_id'])){
				$productid=addslashes($_POST['product_id']);
				}	
						
				if(isset($_POST['ffa_requested'])){
				$ffarequested=addslashes($_POST['ffa_requested']);
				}	
				
				if(isset($_POST['purchasetype'])){
				$purchasetype=addslashes($_POST['purchasetype']);
				}	
				
				if(isset($_POST['commodity_val'])){
				$commodityval=addslashes($_POST['commodity_val']);
				}	
				
				if(isset($_POST['tin_rate'])){
				$tinrate=addslashes($_POST['tin_rate']);
				}	
				
				if(isset($_POST['commodity_rate_total'])){
				$commodityratetotal=addslashes($_POST['commodity_rate_total']);
				}	
				
				if(isset($_POST['tanker_freight_chg'])){
				$tankerfreightchg=addslashes($_POST['tanker_freight_chg']);
				}	
				
				if(isset($_POST['tonnage_rate'])){
				$tonnagerate=addslashes($_POST['tonnage_rate']);
				}	
				
				if(isset($_POST['tanker_total'])){
				$tankertotal=addslashes($_POST['tanker_total']);
				}	
				
				if(isset($_POST['passing_chg'])){
				$passingchg=addslashes($_POST['passing_chg']);
				}	
				
				if(isset($_POST['tin_rate_comm'])){
				$tinratecomm=addslashes($_POST['tin_rate_comm']);
				}
				
				if(isset($_POST['ffa_got'])){
				$ffagot=addslashes($_POST['ffa_got']);
				}
				
				if(isset($_POST['ffa_given'])){
				$ffagiven=addslashes($_POST['ffa_given']);
				}
				
				if(isset($_POST['rtgs_chg'])){
				$rtgschg=addslashes($_POST['rtgs_chg']);
				}
				
				if(isset($_POST['weight_bridge'])){
				$weightbridge=addslashes($_POST['weight_bridge']);
				}
				
				if(isset($_POST['lab_testing'])){
				$labtesting=addslashes($_POST['lab_testing']);
				}
				
				if(isset($_POST['other_expense'])){
				$otherexpense=addslashes($_POST['other_expense']);
				}
				
				if(isset($_POST['tax_perkg'])){
				$taxper=addslashes($_POST['tax_perkg']);
				}	
				
				if(isset($_POST['tax_total'])){
				$taxtotal=addslashes($_POST['tax_total']);
				}	
				
				if(isset($_POST['grand_total'])){
				$grandtotal=addslashes($_POST['grand_total']);
				}
				
				if(isset($_POST['pass_agent_id'])){
				$passagent_id=addslashes($_POST['pass_agent_id']);
				}
				
				if(isset($_POST['vehicletype'])){
				$vehicletype=addslashes($_POST['vehicletype']);
				}
				
				if(isset($_POST['vehicle_id'])){
				$vehicle_id=addslashes($_POST['vehicle_id']);
				}
				
				if(isset($_POST['drivername'])){
				$drivername=addslashes($_POST['drivername']);
				}
				
				$sqlObj->tablename=$tablename;
				if(isset($_POST['vendor_id']))
				{
				$result=mysql_query("update cf_oilpurchase set 
				pur_vendor_id = '$vendorid',
				pur_prd_id ='$productid',
				pur_ffa_req ='$ffarequested',
				pur_type='$purchasetype',
				pur_com_kg='$commodityval',
				pur_tin_rate='$tinrate',
				pur_com_total='$commodityratetotal',
				pur_tank_tonne='$tankerfreightchg',
				pur_tonne_rate='$tonnagerate',
				pur_tank_total='$tankertotal',
				pur_pass_chg='$passingchg',
				pur_tin_comm='$tinratecomm',
				pur_ffa_got='$ffagot',
				pur_ffa_rate='$ffagiven',
				pur_rtgs_chg='$rtgschg',
				pur_weight_brdg='$weightbridge',
				pur_lab_test='$labtesting',
				pur_other_exp='$otherexpense',
				pur_tax_per='$taxper',
				pur_tax_rate='$taxtotal',
				pur_total ='$grandtotal',
				pur_payable ='$grandtotal',
				pass_agent ='$passagent_id',
				veh_type='$vehicletype',
				vehicleid='$vehicle_id',
				driver_names='$drivername'
				 where pur_id = '$id'");
				
				if(isset($_POST['lab_date'])){
				$labdate= date(('Y-m-d'),strtotime($_POST['lab_date']));
				}
				
				if(isset($_POST['lab_bill_no'])){
				$lab_billno=addslashes($_POST['lab_bill_no']);
				}
				
				if(isset($_POST['lab_quantity'])){
				$labquantity=addslashes($_POST['lab_quantity']);
				}
				
				if(isset($_POST['lab_testing'])){
				$labamount=addslashes($_POST['lab_testing']);
				}
				
				if(isset($_POST['veh_no'])){
				$vehno=addslashes($_POST['veh_no']);
				}
				
				if(isset($_POST['company_name'])){
				$companyname=addslashes($_POST['company_name']);
				}
				
				if(isset($_POST['lab_name'])){
				$labname=addslashes($_POST['lab_name']);
				}
		   
		    $sql4 = mysql_query("update cf_lab lab_date='$labdate',lab_billnum='$lab_billno',lab_qty='$labquantity',lab_bill_amt='$labamount',lab_vehicle_no='$vehno',lab_company='$companyname',lab_name='$labname' where pur_id = '$id'");
				
				header("location:purchase_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 src="js/driverdrop.js"></script>-->
<script src="js/addmoreclient.js"></script>
<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>$(document).ready(function(){
$('#tripdate').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
});

</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.clientform.clientname.value==''){
alert("Enter the Client Name");
document.clientform.clientname.focus();
return false;
}

var cnt = document.getElementById('totcntw').value;

for(i=1;i<=cnt;i++){

	if(document.getElementById('location'+i).value==''){
			alert("Select the town");
			return false;
	}
			
	if(document.getElementById('phoneno'+i).value==''){
		alert("Enter the Phone no");
		return false;
	}
			
	if(document.getElementById('consperson'+i).value==''){
		alert("Enter the Concerned Person");
		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'
});
});	

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

</script>

<script>
	$(document).ready(function() {
		$(".contentkg").css("display","block");


		$('#tin_rate_comm_check').change(function(){

			var tinratecomm = parseInt($("#tin_rate_comm_hidden").val());

			var grand = parseInt($("#grand_total").val());

			if($(this).attr('checked'))
				$("#grand_total").val(grand + tinratecomm);
			else
				$("#grand_total").val(grand - tinratecomm)
		});
	});

function chk_purchase(num)
	{
	
		var comval = '';
		var tinrate = '';
		var comrate_total = '';
		var comrate_grdtotal = '';
		var tankfrechg = '';
		var tonnagerate = '';
		var tankertotal = '';
		var tanker_grdtotal = '';
		var passchg = 0;
		var tinratecomm = 0;
		var ffagiven = 0;
		var rtgschg = 0;
		var weightbridge = 0;
		var labtesting = 0;
		var otherexpense = 0;
		var taxper = '';
		var grandtotal = '';
		var taxgrandtotal = 0;
		var ffagot =0;
		var ffarequested=0;
		var ffaresult=0;
		var getffa=0;
		var ffatotal=0;
		
		//alert(num);
		
		if(num == 1) {
		//alert('a');
			$(".contentin").css("display","none");
			$(".contentjar").css("display","none");
			$(".contentkg").css("display","block");
		  tax_per = document.getElementById("tax_perkg").value;
		  document.getElementById("tax_perkg").style.display="block";
		  document.getElementById("tax_pertin").style.display="none";
		  
		}
		//alert('app')
		//alert(num);
		//tax_per = num;
 
		/*else if(num == 2) {
		 
		  	$(".contentkg").css("display","none");
			$(".contentjar").css("display","none");
		  	$(".contentin").css("display","block");
		  tax_per = document.getElementById("tax_pertin").value;
		  document.getElementById("tax_pertin").style.display="block";
		  document.getElementById("tax_perkg").style.display="none";
		}
		else if(num == 3) {
		
		  	$(".contentkg").css("display","none");
		  	$(".contentin").css("display","none");
			$(".contentjar").css("display","block");
		  tax_per = document.getElementById("tax_pertin").value;
		  document.getElementById("tax_pertin").style.display="block";
		  document.getElementById("tax_perkg").style.display="none";
		}*/
		
		
		
		
		
		
		//exit;
		if(document.getElementById('commodity_val').value !='')
		{
			comval = document.getElementById('commodity_val').value;
		}
		else
		{
			comval = 0;	
		}	
		tinrate = document.getElementById('tin_rate').value;
		//comrate_total = (comval/15)*tinrate; 
		comrate_total = comval*tinrate;
		document.getElementById('commodity_rate_total').value = parseFloat(comrate_total).toFixed(2); 
		
		tankfrechg = comval/1000;			
		document.getElementById('tanker_freight_chg').value = tankfrechg;
		
		tonnagerate = document.getElementById('tonnage_rate').value;
		tankertotal = tankfrechg*tonnagerate;
		document.getElementById('tanker_total').value = parseFloat(tankertotal).toFixed(2);	
		
		
		
		tinratecomm = parseFloat((comval/15)*1.5); $("#tin_rate_comm_hidden").val(tinratecomm);			
		
		document.getElementById('tin_rate_comm1').value = tinratecomm;

		if(document.getElementById('commodity_rate_total').value != '')
		{
			comrate_grdtotal = document.getElementById('commodity_rate_total').value;
		}
		else
		{
			comrate_grdtotal = 0;
		}
		
		if(document.getElementById('tanker_total').value != '')
		{
			tanker_grdtotal = document.getElementById('tanker_total').value;
		}
		else
		{
			tanker_grdtotal = 0;
		}
		
		/*if(document.getElementById('passing_chg').value != '')
		{
			passchg = document.getElementById('passing_chg').value;
		}
		else
		{
			document.getElementById('passing_chg').value = 0; 
		}
		
		if(document.getElementById('passing_chg').value != '')
		{
			passchg = document.getElementById('passing_chg').value;
		}
		else
		{
			document.getElementById('passing_chg').value = 0; 
		}*/
		
		if(document.getElementById('rtgs_chg').value !='')
		{
			rtgschg = document.getElementById('rtgs_chg').value;
		}
		else
		{
			rtgschg = 0;
		}
		
		if(document.getElementById('weight_bridge').value !='')
		{
			weightbridge = document.getElementById('weight_bridge').value;
		}
		else
		{
			weightbridge = 0;
		}
		
		/*if(document.getElementById('lab_testing').value !='')
		{
			labtesting = document.getElementById('lab_testing').value;
		}
		else
		{
			labtesting = 0;
		}*/
		
		if(document.getElementById('other_expense').value !='')
		{
			otherexpense = document.getElementById('other_expense').value;
		}
		else
		{
			otherexpense = 0;
		}
		
		if(document.getElementById('other_expense').value !='')
		{
			otherexpense = document.getElementById('other_expense').value;
		}
		else
		{
			otherexpense = 0;
		}
		
		
		//ffagiven = document.getElementById('ffa_given').value;
		
		
		ffarequested = document.getElementById('ffa_requested').value;
		ffagot = document.getElementById('ffa_got').value;
		//alert(parseFloat(ffagot));
		//alert(parseFloat(ffarequested));
		if(ffagot != '' && ffarequested !='')
		{
			ffaval = parseFloat(ffagot) - parseFloat(ffarequested);
			var ffa = parseFloat(ffaval).toFixed(1);
			//alert(ffa);
			getffa = ffa*10;		
			ffaresult = (comval/15)*getffa;
			//alert(ffaresult);
			
			document.getElementById('ffa_given').value = ffaresult.toFixed(2);
			
			if(document.getElementById('ffa_given').value != '')
			{
				ffatotal = document.getElementById('ffa_given').value;
			}
			else
			{
				ffatotal = 0;
			}
		}	
		
		tax_per = document.getElementById("tax_perkg").value; // nithya
		//alert(tax_per);
		//alert(comrate_grdtotal);			
		taxtotal = (tax_per/100)*comrate_grdtotal;	
		//alert(taxtotal);	
		document.getElementById('tax_total').value = taxtotal.toFixed(2);
		
		if(document.getElementById('tax_total').value != '')
		{
			taxgrandtotal = document.getElementById('tax_total').value;
		}
		else
		{
			taxgrandtotal = 0;
		}
		
		
		//grandtotal = parseInt(passchg) + parseInt(tinratecomm) + rtgschg + parseInt(weightbridge) + labtesting + otherexpense;
		
		/*grandtotal = parseFloat(comrate_grdtotal) + parseFloat(tanker_grdtotal) + parseFloat(passchg) + parseFloat(tinratecomm) + parseFloat(rtgschg) + parseFloat(weightbridge) + parseFloat(labtesting) + parseFloat(otherexpense) + parseFloat(taxgrandtotal) + parseFloat(ffatotal);*/
		
		if(!$('#tin_rate_comm_check').attr('checked'))
			tinratecomm = 0;

		grandtotal = parseFloat(comrate_grdtotal) + parseFloat(tanker_grdtotal) +  parseFloat(tinratecomm) + parseFloat(rtgschg) + parseFloat(weightbridge) + parseFloat(otherexpense) + parseFloat(taxgrandtotal) ;
		
		document.getElementById('grand_total').value = grandtotal.toFixed(2);
		
			
	}



/*$(function(){

   $("input[name=purchasetype]").click(function(){
      $("div.content").not("."+this.value).hide();
      $("."+this.value).show();
   });

});*/



</script>

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

body {
	padding:0px;
	margin:0px;
	font-family:Arial, Helvetica, sans-serif;
	color:#000000;
}
.div01 {
	width:80%;
		margin:0 70px;
	padding-bottom:15px;
}
.ptForm {
	/*border:1px solid #000000;*/
	width:100%;
	margin:0 auto;
	padding:4px;
}
.ptText01 {
	font-size:20px;
	font-weight:bold;
}
.ptText02 {
	font-size:12px;
}
.ptText03 {
	font-size:16px;
	font-weight:bold;
}
.ptText04 {
	font-size:16px;
	font-weight:bold;
	border-left:solid 1px #000000;
	border-right:solid 1px #000000;
	border-top:solid 1px #000000;
}
.ptText05 {
	font-size:14px;
	font-weight:bold;
}
.field01 {
	border-bottom:#333333 dotted 1px;
	border-left:none;
	border-top:none;
	border-right:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.field02 {
	border:none;
	color:#000000;
	font-size:12px;
	font-weight:bold;
	background-color:#f1f1f1;
}
.ptText06 {
	font-size:12px;
	font-weight:bold;
}
.rightTd {
	border-bottom:solid 1px #000000;
}
.leftTd {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.tdItem {
	border-bottom:solid 1px #000000;
	border-right:solid 1px #000000;
	padding:4px;
}
.rightTd {
	border-bottom:solid 1px #000000;
	padding:4px;
}
/*.rightTdBtm {
	border:none;
	padding:4px;
}
.leftTdBtm {
	border-right:solid 1px #000000;
	padding:4px;
}*/
.tdItemBtm {
	
	padding:4px;
}

#adv{

	display:none;
	
}

</style>



</head>

<body onLoad="showkg()">
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 
<div class="tabbedArea">
<?php
/*if(!empty($_REQUEST['tripid']))
{ 
	$tripid1 = $_REQUEST['tripid'];
	$arrtrip1=mysql_query("select * from cf_tripsheetsub where trip_id = '$tripid1'");
	$cnttrip1=mysql_num_rows($arrtrip1);
	if($cnttrip1>0){
		$div = $cnttrip1;
	}else{
		$div=1;
	}
}else{
		$div=1;
}*/
	$div=1;	
	?>
    <input type="hidden" id="divcnt" name="divcnt" value="<?=$div?>"/>
  <div class="tabBody">
  <?php 
		if(empty($_REQUEST['clientsubid']))
		{ ?>
		  <h1>Add Purchase</h1>
		<?php } else { ?>
		  <h1>Edit Purchase</h1>
		<?php }
  ?>
   
   <div class="div01">
  <div class="ptForm">
  <form name="clientform" id="clientform" method="post" >
    <table width="100%" border="0" cellspacing="5" cellpadding="2"  style="border:1px solid #000000; padding:4px;">
           
      <input type="hidden" name="totcnt" id="totcntw" value="<?=$div?>">
     
        
        <!--<td class="ptText06" style="text-align:left;">No.
          <input name="" type="text" class="field02"  style="width:82%;" /></td>-->
          <?php 
		  
		  	$rbilltype = '';
            if(empty($_REQUEST['clientsubid']))
				{ 
					/*$clientsubid =$_REQUEST['clientsubid'];
					$arrclientid=mysql_query("select * from cf_client where client_sub_id = '$clientsubid'");
					$rws = mysql_fetch_array($arrclientid);
					$rbilltype = $rws['client_bill'];*/
				?>
        <?php } else  {
			$clientid = $_REQUEST['clientid'];
			
			$clientsubid =$_REQUEST['clientsubid'];
			
			$arrclientid=mysql_query("select * from cf_client where client_sub_id = '$clientsubid'");
			$rws = mysql_fetch_array($arrclientid);
			
			$clientaut = $rws['client_newcode'];
			$clientbill = $rws['client_billing'];
			$arrclient=mysql_query("select * from cf_client_parent where client_id = '$clientid'");
			$cntclient=mysql_fetch_array($arrclient);
			$cntclient['client_name'];	
			//$clientbill = $cntclient['client_bill'];	
		?>
          <?php } ?>
         
      <tr>
        <td  colspan="5"  class="ptText02" style="width:70%;">
        <div id="list">
        <table width="100%"  cellspacing="0" cellpadding="0"   class="List" align="center" style="border-top:solid 1px #000000; border-bottom:none; border-left:solid 1px #000000; border-right:solid 1px #000000;" >
			 <tr >
              <td class="tdItem" style="font-weight:bold;" colspan="4">Purchase Date
			 
			  	<input type="text" name="purchase_date" id="purchase_date" style="width:100px;" maxlength="100" class="input1" value="<?=$puraddate?>" />
			  </td>
             
            </tr>
            <tr>
              <td class="tdItem" style="font-weight:bold;">Vendor</td>
              <td class="tdItem" style="font-weight:bold;">Product</td>
              <td class="tdItem" style="font-weight:bold;">FFA</td>
              <td class="tdItem" style="font-weight:bold;">Purchase Type</td>
            </tr>
          
             <tr>
             <td class="tdItem">
              <select class="input1" name="vendor_id" id="vendor_id" >
     			<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>    	 </td>
              <td class="tdItem">
              <select class="input1" name="product_id" id="product_id" >
     			<option value="">Select Product</option>
     			<?php 
					$sq_product="select * from cf_open_oil";
					$array1=mysql_query($sq_product);
					while($resprd=mysql_fetch_array($array1))
					{
					?>     	
        				<option value="<?=$resprd['open_stock_id']?>" <? if($resprd['open_stock_id']==$purprdid) {?>selected<? }?>><?=$resprd['item_name']?></option>
               		<?php
					}
	 				?>
     		</select>    	 </td>
              
              <td class="tdItem">
			   <input type="text" name="ffa_requested" id="ffa_requested" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purffareq?>">
              	<?php /*?><select class="input1" name="ffa_requested" id="ffa_requested"  >
                <option value="">Select FFA</option>
                    <option value="0.8" <? if($purffareq=='0.8') {?>selected<? }?>>0.8</option>
                    <option value="0.9" <? if($purffareq=='0.9') {?>selected<? }?>>0.9</option>
                    <option value="1.0" <? if($purffareq=='1.0') {?>selected<? }?>>1.0</option>
                    <option value="1.1" <? if($purffareq=='1.1') {?>selected<? }?>>1.1</option>
                    <option value="1.2" <? if($purffareq=='1.2') {?>selected<? }?>>1.2</option>
                    <option value="1.3" <? if($purffareq=='1.3') {?>selected<? }?>>1.3</option>
                    <option value="1.4" <? if($purffareq=='1.4') {?>selected<? }?>>1.4</option>
                    <option value="1.5" <? if($purffareq=='1.5') {?>selected<? }?>>1.5</option>     			
     		   </select><?php */?>             </td>
              <td class="tdItem" >
              	<table width="20%" border="1">
                  <tr>
                    <td><input type="radio" name="purchasetype" id="purchasetype" value="1" onClick="chk_purchase(this.value);" <?php if($purtype==1){?> checked <?php } ?> ></td>
                    <td>Kg</td> 
                    <?php /*?><td>|</td> 
                    <td><input type="radio" name="purchasetype" id="purchasetype" value="2" onClick="chk_purchase(this.value);" ></td>
                    <td>Tin</td>
					<td>|</td> 
					<td><input type="radio" name="purchasetype" id="purchasetype" value="3" onClick="chk_purchase(this.value);" ></td>
                    <td>Jar</td><?php */?>
                  </tr>
            	</table>		 </td>
            </tr>
           
            <tr>
                <td class="tdItem">
                  Commodity Rate                </td>
                <td class="tdItem">
                  <input type="text" name="commodity_val" id="commodity_val" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purcomkg?>">Kg                </td>
                <td class="tdItem"><div style="width:200px; float:left">
                  <input type="text" name="tin_rate" id="tin_rate" class="input1" style="width:175px;" onKeyUp="chk_purchase();" value="<?=$purtinrate?>">
				  <p class="contentin" style="display:none;">Tin </p>
				  <p class="contentkg" style="display:none;">Kg</p>
				  <p class="contentjar" style="display:none;">Jar</p>
				         Rate         </div></td>              
                <td class="tdItem">
                  <input type="text" name="commodity_rate_total" id="commodity_rate_total" class="input1" style="width:175px;" value="<?=$purcomtotal?>" >                </td>  
            </tr>
            
            <tr>
                <td class="tdItem">
                  Tanker Freight                </td>
                <td class="tdItem">
                  <input type="text" name="tanker_freight_chg" id="tanker_freight_chg" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purtanktonne?>" >
                  Tonne                </td>
                <td class="tdItem">
                  <input type="text" name="tonnage_rate" id="tonnage_rate" class="input1" style="width:175px;" onKeyUp="chk_purchase();" value="<?=$purtonnerate?>" >Tonnage Rate                </td>              
                <td class="tdItem">
                  <input type="text" name="tanker_total" id="tanker_total" class="input1" style="width:175px;" value="<?=$purtanktotal?>">                </td>  
            </tr>
			
			
            <tr>
                <td class="tdItem">
                  Tin Rate Commission   <input type="checkbox" name="tin_rate_comm_check" id="tin_rate_comm_check" checked="" value="1"> </td>
                <td class="tdItem">
                	<input type="hidden" id="tin_rate_comm_hidden" value="">
                  <input type="text" name="tin_rate_comm" id="tin_rate_comm1" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purtincomm?>" >
                  Rs</td> 
				  <td class="tdItem" colspan="2" align="center" style="font-weight:bold;">Passing Charge {
				  <input type="radio" name="vehicletype" id="vehicletype" value="1" <?php if($veh_type==1){?> checked <?php } ?>> Big Vehicle ||
				  <input type="radio" name="vehicletype" id="vehicletype" value="2" <?php if($veh_type==2){?> checked <?php } ?>> Smail Vehicle }</td> 
             </tr>
             
            <tr>
                <td class="tdItem">
                  FFA                </td>
                <td class="tdItem">
				 <input type="text" name="ffa_got" id="ffa_got" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purffa_got?>">
				<?php /*?><select class="input1" name="ffa_got" id="ffa_got" onChange="chk_purchase()" >
                  <option value="">Select FFA</option>
                  	<option value="0.8" <? if($purffa_got=='0.8') {?>selected<? }?>>0.8</option>
                    <option value="0.9" <? if($purffa_got=='0.9') {?>selected<? }?>>0.9</option>
                    <option value="1.0" <? if($purffa_got=='1.0') {?>selected<? }?>>1.0</option>
                    <option value="1.1" <? if($purffa_got=='1.1') {?>selected<? }?>>1.1</option>
                    <option value="1.2" <? if($purffa_got=='1.2') {?>selected<? }?>>1.2</option>
                    <option value="1.3" <? if($purffa_got=='1.3') {?>selected<? }?>>1.3</option>
                    <option value="1.4" <? if($purffa_got=='1.4') {?>selected<? }?>>1.4</option>
                    <option value="1.5" <? if($purffa_got=='1.5') {?>selected<? }?>>1.5</option>     			
                </select><?php */?>
                  <input type="text" name="ffa_given" id="ffa_given" class="input1" style="width:75px;" readonly="readonly" value="<?=$purffarate?>"  >
                  Rs</td>
				  
				  <td class="tdItem">Passing Charge   </td>
				  <td class="tdItem"><select class="input1" name="pass_agent_id" id="pass_agent_id" >
     			<option value="">Passing Agent</option>
     			<?php 
					$sq_pass="select * from cf_passing";
					$arrpass=mysql_query($sq_pass);
					while($respass=mysql_fetch_array($arrpass))
					{
					?>     	
        				<option value="<?=$respass['pass_id']?>" <?php if($passagent==$respass['pass_id']){?> selected <?php } ?>><?=$respass['passname']?></option>
               		<?php
					}
	 				?>
     		</select>    
				
                  <input type="text" name="passing_chg" id="passing_chg" class="input1" style="width:75px;" value="<?=$purpasschg?>" >
                  Rs</td>
             </tr>
            
            <tr>
                <td class="tdItem">
                  RTGS Charges                </td>
                <td class="tdItem">
                  <input type="text" name="rtgs_chg" id="rtgs_chg" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purrtgschg?>" >
                  Rs</td>
				  
				  <td class="tdItem" colspan="2" align="center" style="font-weight:bold;">Lab Result </td>
				  
             </tr>
             
            <tr>
                <td class="tdItem">
                  Weight Bridge                </td>
                <td class="tdItem">
                  <input type="text" name="weight_bridge" id="weight_bridge" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purweightbrdg?>" >
                  Rs</td>
				  <td class="tdItem">Date</td>
				  <td class="tdItem"><input type="text" name="lab_date" id="lab_date" style="width:100px;" maxlength="100" class="input1" value="<?=$lab_date_1?>" /></td>
             </tr>
             
            
             
            <tr>
                <td class="tdItem">
                  Other Expense                </td>
                <td class="tdItem">
                  <input type="text" name="other_expense" id="other_expense" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purotherexp?>">
                  Rs</td>
				  
				  <td class="tdItem">Bill No</td>
				  <td class="tdItem"><input type="text" name="lab_bill_no" id="lab_bill_no" class="input1" value="<?=$lab_billnum_1?>" ></td>
             </tr>
             
            <tr>
                <td class="tdItem">Tax</td>
                <td class="tdItem">
                  <select class="input1 tax_packages" name="tax_perkg" id="tax_perkg" onChange="chk_purchase()">
                	<option value="">Select Tax</option>
                    <option value="2" <? if($purtaxper=='2') {?>selected<? }?>>2%</option>
                    <option value="5" <? if($purtaxper=='5') {?>selected<? }?>>5%</option>
                  </select>	
                  
                  <?php /*?><select class="input1 tax_packages" name="tax_per" id="tax_pertin" onChange="chk_purchase()" style="display:none;" >
                	<option value="">Select Tax</option>
                    <option value="2" <? if($purtaxper=='2') {?>selected<? }?>>2%</option>          
                  </select>	<?php */?>
                 
                  <input type="text" name="tax_total" id="tax_total" class="input1" style="width:75px;" onKeyUp="chk_purchase();" value="<?=$purtaxrate?>" >
                  Rs</td>
				  
				  <td class="tdItem">Quantity</td>
				  <td class="tdItem"><input type="text" name="lab_quantity" id="lab_quantity" class="input1" value="<?=$lab_qty_1?>" ></td>
			</tr>
             
            <tr>
                <td class="tdItem" style="font-weight:bold;">Total</td>
                <td class="tdItem">
                  <input type="text" name="grand_total" id="grand_total" class="input1" style="width:75px;" value="<?=$purtotal?>" >
                  Rs</td>
				  <td class="tdItem">Bill Amount</td>
				  <td class="tdItem"><input type="text" name="lab_testing" id="lab_testing" class="input1" value="<?=$lab_bill_amt_1?>" ></td>
			</tr>
			 
			 <tr>
                <td class="tdItem"></td>
                <td class="tdItem"></td>
				<td class="tdItem">Company Name</td>
				<td class="tdItem"><input type="text" name="company_name" id="company_name" class="input1"  value="<?=$lab_company_1?>" ></td>
			</tr>
			 
			 <tr>
                <td class="tdItem">Vehicle No</td>
                <td class="tdItem"><select class="input1" name="vehicle_id" id="vehicle_id" >
     			<option value="">Vehicle No</option>
     			<?php 
					$sq_veh="select * from cf_vehicle";
					$arrveh=mysql_query($sq_veh);
					while($resveh=mysql_fetch_array($arrveh))
					{
					?>     	
        				<option value="<?=$resveh['id']?>" <?php if($vehicleid==$resveh['id']){?> selected <?php } ?>><?=$resveh['vehiclenum']?></option>
               		<?php
					}
	 				?>
     		</select>    </td>
				 <td class="tdItem">Vehicle No</td>
                <td class="tdItem"><input type="text" name="veh_no" id="veh_no" class="input1"  value="<?=$lab_vehicle_no_1?>" ></td>
			 </tr>
			 
			 <tr>
               
				<td class="tdItem">Driver Name</td>
				<td class="tdItem"><input type="text" name="drivername" id="drivername" class="input1"  value="<?=$driver_names?>" ></td>
				<td class="tdItem">Lab Name</td>
				<td class="tdItem"><input type="text" name="lab_name" id="lab_name" class="input1" value="<?=$lab_name_1?>" ></td>
			 </tr>
          </table> 
          </div>
                </td>
      </tr>
        
            
            <tr>
            	<td width="825">
                <?php 
                 	if(empty($_REQUEST['pur_mainid']))
					{ ?>
					  <input type="submit" name="purchasesubmit" value="submit" class="submit-btn" onClick="return validation()"  >
                <?php } else { ?>
                	  <input type="submit" name="clientedit" value="edit" class="submit-btn" onClick="return validation()"  >
                <?php } ?>                </td>
            </tr>    
    </table>
    
    </form>
    
  </div>
  <div style="text-align:center;">
    
  </div>
</div>
   </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>


		






