<?
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';


			
			$lab_date='';	
			$lab_billnum='';	
			$lab_qty='';	
			$lab_bill_amt='';	
			$lab_vehicle_no='';						
			$lab_company='';
			$lab_name='';	
			$purpasschg = '';
			$vehicle_type='';	
			$pass_agent_id='';	
			$passing_chg='';
		$todaydate = date('Y-m-d H:i:s');	
		if(isset($_POST['jarsubmit'])){
		
			
			if(isset($_POST['clientid'])){
			$clientid=addslashes($_POST['clientid']);
			}	
			
			if(isset($_POST['no_of_jar'])){
			$numjar=addslashes($_POST['no_of_jar']);
			}	
			
			if(isset($_POST['jar_rate'])){
			$jarate=addslashes($_POST['jar_rate']);
			}
			
			if(isset($_POST['jar_amount'])){
			$jaramount=addslashes($_POST['jar_amount']);
			}
			
			if(isset($_POST['purchase_date'])){
			$purchase_date = date(('Y-m-d'),strtotime($_POST['purchase_date']));
			}
			
			$sql2 = mysql_query("insert into cf_jar_purchase (jar_purchase_type,jar_clientid,jar_no,jar_amount,jar_per_rate,date) values 
			('jar_sales','$clientid','$numjar','$jaramount','$jarate','$purchase_date')");
			
			$purid = mysql_insert_id();
			
			mysql_query("update cf_stock set `stock_jar`=`stock_jar`-$numjar");
			
			$reselleres = mysql_query("select * from cf_ledger where ledgertype = 'clientledger' and empid = '$clientid'");
			$resellrw = mysql_fetch_array($reselleres);
			$ledgerids = $resellrw['ledgerid'];
			
			mysql_query("update  cf_accountsreceivable set `receiveamount`=`receiveamount`+$jaramount where clientid=$clientid");  
			
			$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) values ('$purid','$jaramount','1','1134','$purchase_date','$todaydate','$acc_reference')");
		   
		   
		   $sql32 = mysql_query("insert into cf_purchase_account (purchaseid,acc_amount,account_type,ven_client_id,pay_date,add_date,account_reference) values ('$purid','$jaramount','2','$ledgerids','$purchase_date','$todaydate','$acc_reference')");	
			  
		//$purid = mysql_insert_id();
		header("location:jar_sales_list.php");
		}
		
		
		if(isset($_REQUEST['lab_id'])){
			$id=$_REQUEST['lab_id'];
			//$tablename='cf_lab';
			$sqlObj->tablename="cf_lab";
			$condition=" where lab_id='$id'";
			$sqlObj->condition=$condition;
			$sqlObj->fieldvalue="*";
			$fieldvalue=$sqlObj->fieldvalue;
			$sql=$sqlObj->SelectTable();

			$lab_date=date(('d-m-Y'),strtotime($sql['lab_date']));
			$lab_billnum=$sql['lab_billnum'];	
			$lab_qty=$sql['lab_qty'];	
			$lab_bill_amt=$sql['lab_bill_amt'];	
			$lab_vehicle_no=$sql['lab_vehicle_no'];					
			$lab_company=$sql['lab_company'];
			$lab_name=$sql['lab_name'];	
			$vehicle_type=$sql['vehicle_type'];	
			$pass_agent_id=$sql['pass_agent_id'];	
			$passing_chg=$sql['passing_chg'];	

		}
		
		
		if(isset($_POST['jaredit']))
		{
			
			if(isset($_POST['lab_date'])){
			$lab_date=date(('Y-m-d'),strtotime($_POST['lab_date']));
			}
			
			if(isset($_POST['lab_bill_no'])){
			$lab_bill_no=addslashes($_POST['lab_bill_no']);
			}	
					
			if(isset($_POST['lab_quantity'])){
			$lab_quantity=addslashes($_POST['lab_quantity']);
			}	
			
			if(isset($_POST['bill_amt'])){
			$bill_amt=addslashes($_POST['bill_amt']);
			}	
			
			if(isset($_POST['company_name'])){
			$company_name=addslashes($_POST['company_name']);
			}	
			
			if(isset($_POST['veh_no'])){
			$veh_no=addslashes($_POST['veh_no']);
			}	
			
			if(isset($_POST['lab_agent_id'])){
			$lab_agent_id=addslashes($_POST['lab_agent_id']);
			}	
			
			if(isset($_POST['vehicletype'])){
			$vehicletype=addslashes($_POST['vehicletype']);
			}	
			
			if(isset($_POST['pass_agent_id'])){
			$pass_agent_id=addslashes($_POST['pass_agent_id']);
			}	
			
			if(isset($_POST['passing_chg'])){
			$passing_chg=addslashes($_POST['passing_chg']);
			}	
			
			//$today = date('Y-m-d');
			
			  $sql3 = mysql_query("update cf_lab set lab_date='$lab_date',lab_billnum='$lab_bill_no',lab_qty='$lab_quantity',lab_bill_amt='$bill_amt',lab_vehicle_no='$veh_no',lab_company='$company_name',lab_name='$lab_agent_id',vehicle_type='$vehicletype',pass_agent_id='$pass_agent_id',passing_chg='$passing_chg' where lab_id=$id");
			//$purid = mysql_insert_id();
		header("location:lab_test_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 chk_jar_sales(num)
	{
	var no_ofjar='';
	var jarrate_total=0;
	if(document.getElementById('no_of_jar').value !='')
		{
			no_ofjar = document.getElementById('no_of_jar').value;
		}
		else
		{
			no_ofjar = 0;	
		}	
		
		jarate = document.getElementById('jar_rate').value;
		//comrate_total = (comval/15)*tinrate; 
		jarrate_total = no_ofjar*jarate;
		document.getElementById('jar_amount').value = jarrate_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 Jar Sales </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" >
            
       
       
       <br/>
	<div>     
	
	</div>

	

	<div>     
	<p class="input1">No of Jar<span style="color:#FF3300">*</span></p>
	<input type="text" name="no_of_jar" id="no_of_jar" class="input1" onKeyUp="chk_jar_sales();" value="" >
	</div> 
	
	<div>     
	<p class="input1">Per Jar Rate</p><input type="text" name="jar_rate" id="jar_rate" class="input1" onKeyUp="chk_jar_sales();" value="" >
	</div>
	
	<div>     
	<p class="input1">Amount</p><input type="text" name="jar_amount" id="jar_amount" class="input1" value="" readonly="readonly" >
	</div>




	</div>
	</td>
	<td valign="top"><div class="form1">
	
	<div>     
	<p class="input1">Date<span style="color:#FF3300">*</span></p>
	<input type="text" name="purchase_date" id="purchase_date" style="width:100px;" maxlength="100" class="input1" value="" />
	</div> 
	
	<div>     
	<p class="input1">Client<span style="color:#FF3300">*</span></p>
	<select class="input1" name="clientid" id="clientid"  >
                  <option value="">Select Client</option>
                  <?php 
					$sq_client="select * from cf_client";
					$arrclient=mysql_query($sq_client);
					while($resclt=mysql_fetch_array($arrclient))
					{
					?>
                  <option value="<?=$resclt['client_id']?>"    >
                    <?=$resclt['client_name']?>
                    </option>
                  <?php
					}
	 				?>
                </select>   
	</div>    

	       <div>
            &nbsp;
            </div>
            </div></td>
          </tr>
           <tr>
            <td colspan="2"><div class="searchField1">
        
           
                <?php 
                 	if(empty($_REQUEST['lab_id']))
					{ ?>
					  <input type="submit" name="jarsubmit" value="submit" class="submit-btn" onClick="return validation_1()"  >
                <?php } else { ?>
                	  <input type="submit" name="jaredit" 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>


		






